· 7 years ago · Sep 11, 2018, 05:46 PM
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/* Exclude BuddyPress Users from Showing Up Anywhere */
15function millionairesdigest_exclude_users( $args ) {
16 //do not exclude in admin
17 if( is_admin() && ! defined( 'DOING_AJAX' ) ) {
18 return $args;
19 }
20 $excluded = isset( $args['exclude'] )? $args['exclude'] : array();
21 if( !is_array( $excluded ) ) {
22 $excluded = explode(',', $excluded );
23 }
24 $user_ids = array( 836 ); //User IDs
25 $excluded = array_merge( $excluded, $user_ids );
26 $args['exclude'] = $excluded;
27 return $args;
28}
29add_filter( 'bp_after_has_members_parse_args', 'millionairesdigest_exclude_users' );
30
31
32/* Remove Public Message Button */
33add_filter('bp_get_send_public_message_button', '__return_false');
34
35
36/* Rename Private Message Button */
37function millionairesdigest_private_message_button_label ( $args ) {
38 $args[link_text] = 'Message';
39 return $args;
40}
41add_filter( 'bp_get_send_message_button_args', 'millionairesdigest_private_message_button_label', 1, 1 );
42
43
44/* Remove the Private Message Button Eveywhere (Especially the Member Directory) as It's Not Neccessarily Helpful to Our Users When They Use the Matchmaker to Do Searches, and Allow It to Only Be Displayed in Member Header if On or Viewing a User's Profile */
45function millionairesdigest_remove_private_message_button() {
46 add_filter( 'bp_get_send_message_button', '__return_false' );
47}
48if ( bp_is_active( 'messages' ) ) {
49 add_action( 'bp_directory_members_actions', 'millionairesdigest_remove_private_message_button' );
50}
51
52
53/* Remove the WYSIWYG Editor from Users Profile Fields */
54add_filter( 'bp_xprofile_is_richtext_enabled_for_field', '__return_false' );
55
56
57/* Adjust the size of the BuddyPress Avatars */
58define ( 'BP_AVATAR_THUMB_WIDTH', 250 );
59define ( 'BP_AVATAR_THUMB_HEIGHT', 250 );
60define ( 'BP_AVATAR_FULL_WIDTH', 512 );
61define ( 'BP_AVATAR_FULL_HEIGHT', 512 );
62
63
64/* Rename All of the Following Subnav Tabs in User's Messages */
65function change_profile_submenu_tabs(){
66 global $bp;
67 $bp->bp_options_nav['messages']['inbox']['name'] = 'All Messages';
68 $bp->bp_options_nav['messages']['starred']['name'] = 'Liked Messages';
69 $bp->bp_options_nav['messages']['sentbox']['name'] = 'Sent Messages';
70 $bp->bp_options_nav['messages']['compose']['name'] = 'New Message';
71 $bp->bp_options_nav['settings']['notifications']['name'] = 'Notifications';
72 $bp->bp_options_nav['friends']['my-friends']['name'] = 'Friends';
73 $bp->bp_options_nav['settings']['profile']['name'] = 'Visibility Overview';
74}
75add_action('bp_setup_nav', 'change_profile_submenu_tabs', 999);
76
77
78/* Remove the Following Admin Dashboad Widgets to Prevent Them from Showing Up on the Backend Dashboard Main Page */
79function remove_admin_dashboard_widgets() {
80 global $wp_meta_boxes;
81 unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
82 unset($wp_meta_boxes['dashboard']['normal']['core']['ctdl']);
83 unset($wp_meta_boxes['dashboard']['normal']['core']['arve_dashboard_widget']);
84 unset($wp_meta_boxes['dashboard']['normal']['core']['pmpro_db_widget']);
85 unset($wp_meta_boxes['dashboard']['normal']['core']['rtmedia_dashboard_widget']);
86}
87add_action('wp_dashboard_setup', 'remove_admin_dashboard_widgets', 999);
88
89
90/* Hide the Following Categories from All of the Following Company Members and Users Who Do Not Have the "view_private_company_categories" Capability so That They Cannot Access nor Accidently Post Their Articles in Them */
91function millionairesdigest_private_categories( $exclusions, $args ) {
92 global $pagenow;
93 if ( in_array( $pagenow,array( 'post-new.php' ) ) && !current_user_can( 'add_posts_to_company_categories') ) {
94 $exclusions = " {$exclusions} AND t.slug NOT IN ('featured', 'private-categories', 'company-news', 'magazine-news', 'platform-news', 'company-announcements', 'company-new-releases-and-features', 'company-reports', 'platform-contributors', 'platform-photographers', 'platform-authors', 'platform-editors', 'platform-publishers', 'magazine-authors', 'magazine-photographers', 'magazine-editors', 'magazine-designers', 'magazine-publishers', 'live-events', 'millionaires-digest-magazine', 'millionaires-digest-timeline')";
95 }
96 return $exclusions;
97}
98add_filter('list_terms_exclusions', 'millionairesdigest_private_categories', 10, 2);
99
100
101/* Add Support for Showing Custom Post Type "Articles" in BuddyPress Activity Streams */
102function article_activity_args() {
103 if ( ! bp_is_active( 'activity' ) ) {
104 return;
105 }
106 add_post_type_support( 'article', 'buddypress-activity' );
107 bp_activity_set_post_type_tracking_args( 'article', array(
108 'component_id' => 'activity',
109 'action_id' => 'new_article',
110 'bp_activity_admin_filter' => __( 'Wrote a new article', 'text-domain' ),
111 'bp_activity_front_filter' => __( 'Articles', 'text-domain' ),
112 'contexts' => array( 'activity', 'member' ),
113 'activity_comment' => true,
114 'bp_activity_new_post' => __( '%1$s wrote a new article, <a href="%2$s">[Article]</a>', 'text-domain' ),
115 'position' => 100,
116 ) );
117}
118add_action( 'init', 'article_activity_args' );
119function article_include_post_type_title( $action, $activity ) {
120 if ( empty( $activity->id ) ) {
121 return $action;
122 }
123 if ( 'new_article' != $activity->type ) {
124 return $action;
125 }
126 preg_match_all( '/<a.*?>([^>]*)<\/a>/', $action, $matches );
127 if ( empty( $matches[1][1] ) || '[Article]' != $matches[1][1] ) {
128 return $action;
129 }
130 $post_type_title = bp_activity_get_meta( $activity->id, 'post_title' );
131 if ( empty( $post_type_title ) ) {
132 switch_to_blog( $activity->item_id );
133 $post_type_title = get_post_field( 'post_title', $activity->secondary_item_id );
134 if ( ! empty( $post_type_title ) ) {
135 bp_activity_update_meta( $activity->id, 'post_title', $post_type_title );
136 }
137 restore_current_blog();
138 }
139 return str_replace( $matches[1][1], esc_html( $post_type_title ), $action );
140}
141add_filter( 'bp_activity_custom_post_type_post_action', 'article_include_post_type_title', 10, 2 );
142
143
144/* Add Support for Showing Custom Post Type "Videos" in BuddyPress Activity Streams */
145function video_activity_args() {
146 if ( ! bp_is_active( 'activity' ) ) {
147 return;
148 }
149 add_post_type_support( 'video', 'buddypress-activity' );
150 bp_activity_set_post_type_tracking_args( 'video', array(
151 'component_id' => 'activity',
152 'action_id' => 'new_video',
153 'bp_activity_admin_filter' => __( 'Uploaded a new video', 'text-domain' ),
154 'bp_activity_front_filter' => __( 'Videos', 'text-domain' ),
155 'contexts' => array( 'activity', 'member' ),
156 'activity_comment' => true,
157 'bp_activity_new_post' => __( '%1$s uploaded a new video, <a href="%2$s">[Video]</a>', 'text-domain' ),
158 'position' => 100,
159 ) );
160}
161add_action( 'init', 'video_activity_args' );
162function video_include_post_type_title( $action, $activity ) {
163 if ( empty( $activity->id ) ) {
164 return $action;
165 }
166 if ( 'new_video' != $activity->type ) {
167 return $action;
168 }
169 preg_match_all( '/<a.*?>([^>]*)<\/a>/', $action, $matches );
170 if ( empty( $matches[1][1] ) || '[Video]' != $matches[1][1] ) {
171 return $action;
172 }
173 $post_type_title = bp_activity_get_meta( $activity->id, 'post_title' );
174 if ( empty( $post_type_title ) ) {
175 switch_to_blog( $activity->item_id );
176 $post_type_title = get_post_field( 'post_title', $activity->secondary_item_id );
177 // We have a title save it in activity meta to avoid switching blogs too much
178 if ( ! empty( $post_type_title ) ) {
179 bp_activity_update_meta( $activity->id, 'post_title', $post_type_title );
180 }
181 restore_current_blog();
182 }
183 return str_replace( $matches[1][1], esc_html( $post_type_title ), $action );
184}
185add_filter( 'bp_activity_custom_post_type_post_action', 'video_include_post_type_title', 10, 2 );
186
187
188/* Add Support for Showing Custom Post Type "Photos" in BuddyPress Activity Streams */
189function photo_activity_args() {
190 if ( ! bp_is_active( 'activity' ) ) {
191 return;
192 }
193 add_post_type_support( 'photo', 'buddypress-activity' );
194 bp_activity_set_post_type_tracking_args( 'photo', array(
195 'component_id' => 'activity',
196 'action_id' => 'new_photo',
197 'bp_activity_admin_filter' => __( 'Uploaded a new photo', 'text-domain' ),
198 'bp_activity_front_filter' => __( 'Photos', 'text-domain' ),
199 'contexts' => array( 'activity', 'member' ),
200 'activity_comment' => true,
201 'bp_activity_new_post' => __( '%1$s uploaded a new photo, <a href="%2$s">[Photo]</a>', 'text-domain' ),
202 'position' => 100,
203 ) );
204}
205add_action( 'init', 'photo_activity_args' );
206function photo_include_post_type_title( $action, $activity ) {
207 if ( empty( $activity->id ) ) {
208 return $action;
209 }
210 if ( 'new_photo' != $activity->type ) {
211 return $action;
212 }
213 preg_match_all( '/<a.*?>([^>]*)<\/a>/', $action, $matches );
214 if ( empty( $matches[1][1] ) || '[Photo]' != $matches[1][1] ) {
215 return $action;
216 }
217 $post_type_title = bp_activity_get_meta( $activity->id, 'post_title' );
218 if ( empty( $post_type_title ) ) {
219 switch_to_blog( $activity->item_id );
220 $post_type_title = get_post_field( 'post_title', $activity->secondary_item_id );
221 // We have a title save it in activity meta to avoid switching blogs too much
222 if ( ! empty( $post_type_title ) ) {
223 bp_activity_update_meta( $activity->id, 'post_title', $post_type_title );
224 }
225 restore_current_blog();
226 }
227 return str_replace( $matches[1][1], esc_html( $post_type_title ), $action );
228}
229add_filter( 'bp_activity_custom_post_type_post_action', 'photo_include_post_type_title', 10, 2 );
230
231
232/* Add Support for Showing Custom Post Type "Music" in BuddyPress Activity Streams */
233function audio_activity_args() {
234 if ( ! bp_is_active( 'activity' ) ) {
235 return;
236 }
237 add_post_type_support( 'audio', 'buddypress-activity' );
238 bp_activity_set_post_type_tracking_args( 'audio', array(
239 'component_id' => 'activity',
240 'action_id' => 'new_audio',
241 'bp_activity_admin_filter' => __( 'Uploaded a new song', 'text-domain' ),
242 'bp_activity_front_filter' => __( 'Music', 'text-domain' ),
243 'contexts' => array( 'activity', 'member' ),
244 'activity_comment' => true,
245 'bp_activity_new_post' => __( '%1$s uploaded a new song, <a href="%2$s">[Song]</a>', 'text-domain' ),
246 'position' => 100,
247 ) );
248}
249add_action( 'init', 'audio_activity_args' );
250function audio_include_post_type_title( $action, $activity ) {
251 if ( empty( $activity->id ) ) {
252 return $action;
253 }
254 if ( 'new_audio' != $activity->type ) {
255 return $action;
256 }
257 preg_match_all( '/<a.*?>([^>]*)<\/a>/', $action, $matches );
258 if ( empty( $matches[1][1] ) || '[Song]' != $matches[1][1] ) {
259 return $action;
260 }
261 $post_type_title = bp_activity_get_meta( $activity->id, 'post_title' );
262 if ( empty( $post_type_title ) ) {
263 switch_to_blog( $activity->item_id );
264 $post_type_title = get_post_field( 'post_title', $activity->secondary_item_id );
265 // We have a title save it in activity meta to avoid switching blogs too much
266 if ( ! empty( $post_type_title ) ) {
267 bp_activity_update_meta( $activity->id, 'post_title', $post_type_title );
268 }
269 restore_current_blog();
270 }
271 return str_replace( $matches[1][1], esc_html( $post_type_title ), $action );
272}
273add_filter( 'bp_activity_custom_post_type_post_action', 'audio_include_post_type_title', 10, 2 );
274
275
276/* Add Support for Allowing Featued Images for Custom Post Type "Articles" to Be Displayed in BuddyPress Activity Streams */
277function article_bp_activity_entry_meta() {
278 if ( bp_get_activity_type() == 'new_article' ) {?>
279 <?php
280 global $wpdb, $post, $bp;
281 $theimg = wp_get_attachment_image_src( get_post_thumbnail_id( bp_get_activity_secondary_item_id() ), 'large' );
282 ?>
283 <img src="<?php echo $theimg[0]; ?>" >
284 <?php }
285}
286add_action('bp_activity_excerpt_append_text', 'article_bp_activity_entry_meta');
287
288
289/* Add Support for Allowing Featued Images for Custom Post Type "Photos" to Be Displayed in BuddyPress Activity Streams */
290function photo_bp_activity_entry_meta() {
291 if ( bp_get_activity_type() == 'new_photo' ) {?>
292 <?php
293 global $wpdb, $post, $bp;
294 $theimg = wp_get_attachment_image_src( get_post_thumbnail_id( bp_get_activity_secondary_item_id() ), 'large' );
295 ?>
296 <img src="<?php echo $theimg[0]; ?>" >
297 <?php }
298}
299add_action('bp_activity_excerpt_append_text', 'photo_bp_activity_entry_meta');
300
301
302/* Add Support for Allowing Custom Post Type "Articles" to be Submitted & Published in BuddyPress Activity Streams and Frontend */
303function generate_article_from_form_submission() {
304 // Get the submitted field values
305 $post_title = af_get_field( 'article_title' );
306 $post_content = af_get_field( 'article_content' );
307 // Set up a form using the values for post title and content
308 // Replace post_type with whatever type of post you want to generate
309 $post_data = array(
310 'post_type' => 'article',
311 'post_status' => 'publish',
312 'post_title' => $post_title,
313 'post_content' => $post_content,
314 );
315 // Create post with the previously retrieved values
316 $post_id = wp_insert_post( $post_data );
317 // Save extra_information field directly to custom field on post
318 af_save_field( '_thumbnail_id', $post_id );
319}
320add_action( 'af/form/submission/key=form_5a6d550fa348b', 'generate_article_from_form_submission', 10 );
321
322
323/* Add Support for Allowing Custom Post Type "Videos" to be Submitted & Published in BuddyPress Activity Streams and Frontend */
324function generate_video_from_form_submission() {
325 // Get the submitted field values
326 $post_title = af_get_field( 'video_title' );
327 $post_content = af_get_field( 'video_link' );
328 // Set up a form using the values for post title and content
329 // Replace post_type with whatever type of post you want to generate
330 $post_data = array(
331 'post_type' => 'video',
332 'post_status' => 'publish',
333 'post_title' => $post_title,
334 'post_content' => $post_content,
335 );
336 // Create post with the previously retrieved values
337 $post_id = wp_insert_post( $post_data );
338 // Save extra_information field directly to custom field on post
339 af_save_field( 'video_content', $post_id );
340}
341add_action( 'af/form/submission/key=form_5a7606d26943d', 'generate_video_from_form_submission', 10 );
342
343
344/* Add Support for Allowing Custom Post Type "Photos" to be Submitted & Published in BuddyPress Activity Streams and Frontend */
345function generate_photo_from_form_submission() {
346 // Get the submitted field values
347 $post_title = af_get_field( 'photo_title' );
348 $post_content = af_get_field( 'photo_content' );
349 // Set up a form using the values for post title and content
350 // Replace post_type with whatever type of post you want to generate
351 $post_data = array(
352 'post_type' => 'photo',
353 'post_status' => 'publish',
354 'post_title' => $post_title,
355 'post_content' => $post_content,
356 );
357 // Create post with the previously retrieved values
358 $post_id = wp_insert_post( $post_data );
359 // Save extra_information field directly to custom field on post
360 af_save_field( '_thumbnail_id', $post_id );
361}
362add_action( 'af/form/submission/key=form_5a76139d04770', 'generate_photo_from_form_submission', 10 );
363
364
365/* Add Support for Allowing Custom Post Type "Music" to be Submitted & Published in BuddyPress Activity Streams and Frontend */
366function generate_audio_from_form_submission() {
367 // Get the submitted field values
368 $post_title = af_get_field( 'audio_title' );
369 $post_content = af_get_field( 'audio_link' );
370 // Set up a form using the values for post title and content
371 // Replace post_type with whatever type of post you want to generate
372 $post_data = array(
373 'post_type' => 'audio',
374 'post_status' => 'publish',
375 'post_title' => $post_title,
376 'post_content' => $post_content,
377 );
378 // Create post with the previously retrieved values
379 $post_id = wp_insert_post( $post_data );
380 // Save extra_information field directly to custom field on post
381 af_save_field( 'audio_artist', $post_id );
382 af_save_field( 'audio_genre', $post_id );
383 af_save_field( 'audio_content', $post_id );
384}
385add_action( 'af/form/submission/key=form_5a7613a051921', 'generate_audio_from_form_submission', 10 );
386
387
388/* Add Support for Single Line WYSIWYG to Advanced Custom Fields Pro */
389define('MEDIUM_EDITOR_THEME', 'kleo');
390define('MEDIUM_EDITOR_THEME', 'kleo-child');
391function kleo_single_line_wysiwyg_editor($theme) {
392 $theme = 'kleo';
393 return $theme;
394}
395add_filter('medium-editor-theme', 'kleo_single_line_wysiwyg_editor');
396function kleo_child_single_line_wysiwyg_editor($theme) {
397 $theme = 'kleo-child';
398 return $theme;
399}
400add_filter('medium-editor-theme', 'kleo_child_single_line_wysiwyg_editor');
401
402
403/* Change Admin Display Name from "Administrator" to "Founder" */
404function change_role_name() {
405 global $wp_roles;
406 if ( ! isset( $wp_roles ) )
407 $wp_roles = new WP_Roles();
408 $wp_roles->role_names['administrator'] = 'Founder';
409}
410add_action('init', 'change_role_name');
411
412
413/* 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. */
414add_action('bp_init', 'md_bpxps_init');
415function md_bpxps_init() {
416 add_shortcode('xprofile', 'md_bpxps_xprofile_shortcode');
417}
418function md_bpxps_xprofile_shortcode($attributes) {
419 if(empty($attributes['field'])) return false;
420 extract($attributes);
421 $user_id = (isset($user)) ? $user : false;
422 global $bp;
423 if (!empty($user_id) && intval($user_id)===0) {
424 // shortcode-defined username
425 $user_id = get_user_by( 'slug', $user_id);
426 }
427 if ((isset($user) && $user=='displayed') ||
428 (empty($user_id) && isset($bp->displayed_user->id))) {
429 // On profile page, show the displayed user's information
430 $user_id = $bp->displayed_user->id;
431 }
432 global $post;
433 if ((isset($user) && $user=='author') ||
434 (empty($user_id) && !empty($post->post_author))) {
435 // On author or single post page, show the author's information
436 $user_id = $post->post_author;
437 }
438 if ((isset($user) && $user=='current') ||
439 (empty($user_id) && is_user_logged_in())) {
440 // Show the currently logged in user's information
441 $user_id = get_current_user_id();
442 }
443 if (empty($user_id)) return false;
444 return xprofile_get_field_data($field, $user_id);
445}
446
447
448/* 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. */
449/* If a YouTube or Vimeo video is added in the post content, grab its thumbnail and set it as the featured image. */
450function millionairesdigest_set_media_as_featured_image( $post_id, $post ) {
451 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
452 return;
453 }
454 if ( wp_is_post_revision( $post_id ) ) {
455 return;
456 }
457 $content = isset( $post->post_content ) ? $post->post_content : '';
458 // Only check the first 800 characters of our post.
459 $content = substr( $content, 0, 800 );
460 // Allow developers to filter the content to allow for searching in postmeta or other places.
461 $content = apply_filters( 'millionairesdigest_featured_images_from_video_filter_content', $content );
462 // Props to @rzen for lending his massive brain smarts to help with the regex.
463 $do_video_thumbnail = (
464 $post_id
465 && ! has_post_thumbnail( $post_id )
466 && $content
467 // Get the video and thumb URLs if they exist.
468 && ( preg_match( '/\/\/(www\.)?(youtu|youtube)\.(com|be)\/(watch|embed)?\/?(\?v=)?([a-zA-Z0-9\-\_]+)/', $content, $youtube_matches )
469 || preg_match( '#https?://(.+\.)?vimeo\.com/.*#i', $content, $vimeo_matches ) )
470 );
471 if ( ! $do_video_thumbnail ) {
472 return update_post_meta( $post_id, '_is_video', false );
473 }
474 $video_thumbnail_url = false;
475 $youtube_id = ! empty( $youtube_matches ) ? $youtube_matches[6] : '';
476 $vimeo_id = ! empty( $vimeo_matches ) ? preg_replace( "/[^0-9]/", "", $vimeo_matches[0] ) : '';
477 if ( $youtube_id ) {
478 // Check to see if our max-res image exists.
479 $remote_headers = wp_remote_head( 'http://img.youtube.com/vi/' . $youtube_id . '/maxresdefault.jpg' );
480 $is_404 = ( 404 === wp_remote_retrieve_response_code( $remote_headers ) );
481 $video_thumbnail_url = ( ! $is_404 ) ? 'http://img.youtube.com/vi/' . $youtube_id . '/maxresdefault.jpg' : 'http://img.youtube.com/vi/' . $youtube_id . '/hqdefault.jpg';
482 } elseif ( $vimeo_id ) {
483 $vimeo_data = wp_remote_get( 'http://www.vimeo.com/api/v2/video/' . intval( $vimeo_id ) . '.php' );
484 if ( isset( $vimeo_data['response']['code'] ) && '200' == $vimeo_data['response']['code'] ){
485 $response = unserialize( $vimeo_data['body'] );
486 $video_thumbnail_url = isset( $response[0]['thumbnail_large'] ) ? $response[0]['thumbnail_large'] : false;
487 }
488 }
489 // If we found an image...
490 $attachment_id = $video_thumbnail_url && ! is_wp_error( $video_thumbnail_url )
491 // Then sideload it.
492 ? 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() ) ) )
493 // No thumbnail url found.
494 : 0;
495 // If attachment wasn't created, bail.
496 if ( ! $attachment_id ) {
497 return;
498 }
499 // Woot! we got an image, so set it as the post thumbnail.
500 set_post_thumbnail( $post_id, $attachment_id );
501 update_post_meta( $post_id, '_is_video', true );
502}
503add_action( 'save_post', 'millionairesdigest_set_media_as_featured_image', 10, 2 );
504/**
505 * Handle the upload of a new image.
506 *
507 * @since 1.0.0
508 *
509 * @param string $url URL to sideload.
510 * @param int $post_id Post ID to attach to.
511 * @param string|null $filename Filename to use.
512 * @return mixed
513 */
514function millionairesdigest_ms_media_sideload_image_with_new_filename( $url, $post_id, $filename = null ) {
515 if ( ! $url || ! $post_id ) {
516 return new WP_Error( 'missing', __( 'Need a valid URL and post ID...', 'automatic-featured-images-from-videos' ) );
517 }
518 require_once( ABSPATH . 'wp-admin/includes/file.php' );
519 // Download file to temp location, returns full server path to temp file, ex; /home/user/public_html/mysite/wp-content/26192277_640.tmp.
520 $tmp = download_url( $url );
521 // If error storing temporarily, unlink.
522 if ( is_wp_error( $tmp ) ) {
523 // Clean up.
524 @unlink( $file_array['tmp_name'] );
525 $file_array['tmp_name'] = '';
526 // And output wp_error.
527 return $tmp;
528 }
529 // Fix file filename for query strings.
530 preg_match( '/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $url, $matches );
531 // Extract filename from url for title.
532 $url_filename = basename($matches[0]);
533 // Determine file type (ext and mime/type).
534 $url_type = wp_check_filetype($url_filename);
535 // Override filename if given, reconstruct server path.
536 if ( !empty( $filename ) ) {
537 $filename = sanitize_file_name( $filename );
538 // Extract path parts.
539 $tmppath = pathinfo( $tmp );
540 // Build new path.
541 $new = $tmppath['dirname'] . '/'. $filename . '.' . $tmppath['extension'];
542 // Renames temp file on server.
543 rename($tmp, $new);
544 // Push new filename (in path) to be used in file array later.
545 $tmp = $new;
546 }
547 /* Assemble file data (should be built like $_FILES since wp_handle_sideload() will be using). */
548 // Full server path to temp file.
549 $file_array['tmp_name'] = $tmp;
550 if ( !empty( $filename ) ) {
551 // User given filename for title, add original URL extension.
552 $file_array['name'] = $filename . '.' . $url_type['ext'];
553 } else {
554 // Just use original URL filename.
555 $file_array['name'] = $url_filename;
556 }
557 $post_data = array(
558 // Just use the original filename (no extension).
559 'post_title' => get_the_title( $post_id ),
560 // Make sure gets tied to parent.
561 'post_parent' => $post_id,
562 );
563 // Required libraries for media_handle_sideload.
564 require_once( ABSPATH . 'wp-admin/includes/file.php' );
565 require_once( ABSPATH . 'wp-admin/includes/media.php' );
566 require_once( ABSPATH . 'wp-admin/includes/image.php' );
567 // Do the validation and storage stuff.
568 // $post_data can override the items saved to wp_posts table, like post_mime_type, guid, post_parent, post_title, post_content, post_status.
569 $att_id = media_handle_sideload( $file_array, $post_id, null, $post_data );
570 // If error storing permanently, unlink.
571 if ( is_wp_error( $att_id ) ) {
572 // Clean up.
573 @unlink( $file_array['tmp_name'] );
574 // And output wp_error.
575 return $att_id;
576 }
577 return $att_id;
578}
579
580
581/* Add Support for Allowing Users to Receive Comment Notifications Left on Their Posts. Note: This includes all post types. */
582class BDBP_Blog_Comment_Notifier {
583 private static $instance;
584 private $id = 'blog_comment_notifier';
585 private function __construct() {
586 $this->setup();
587 }
588 public static function get_instance() {
589 if ( ! isset( self::$instance ) ) {
590 self::$instance = new self();
591 }
592 return self::$instance;
593 }
594 public function setup() {
595 add_action( 'bp_setup_globals', array( $this, 'setup_globals' ) );
596 //On New comment
597 add_action( 'comment_post', array( $this, 'comment_posted' ), 15, 2 );
598 //on delete post, we should delete all notifications for the comment on that post
599 //add_action( 'delete_post', array( $this, 'post_deleted' ), 10, 2 );
600 // Monitor actions on existing comments
601 add_action( 'deleted_comment', array( $this, 'comment_deleted' ) );
602 //add_action( 'trashed_comment', array( $this, 'comment_deleted' ) );
603 //add_action( 'spam_comment', array( $this, 'comment_deleted' ) );
604 //should we do something on the action untrash_comment & unspam_comment
605 add_action( 'wp_set_comment_status', array( $this, 'comment_status_changed' ) );
606 // Load plugin text domain
607 add_action( 'bp_init', array( $this, 'load_textdomain' ) );
608 add_action( 'template_redirect', array( $this, 'mark_read' ) );
609 }
610 public function load_textdomain() {
611 load_plugin_textdomain( 'bp-notify-post-author-on-blog-comment', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
612 }
613 public function setup_globals() {
614 if ( ! defined( 'BD_BLOG_NOTIFIER_SLUG' ) ) {
615 define( 'BD_BLOG_NOTIFIER_SLUG', 'bd-blog-notifier' );
616 }
617 $bp = buddypress();
618 $bp->blog_comment_notifier = new stdClass();
619 $bp->blog_comment_notifier->id = $this->id;//I asume others are not going to use this is
620 $bp->blog_comment_notifier->slug = BD_BLOG_NOTIFIER_SLUG;
621 $bp->blog_comment_notifier->notification_callback = array( $this, 'format_notifications' );//show the notification
622 $bp->active_components[ $bp->blog_comment_notifier->id ] = $bp->blog_comment_notifier->id;
623 do_action( 'blog_comment_notifier_setup_globals' );
624 }
625 public function comment_posted( $comment_id = 0, $comment_status = 0 ) {
626 if ( ! $this->is_bp_active() ) {
627 return ;
628 }
629 $comment = get_comment( $comment_id );
630 if ( empty( $comment ) || $comment->comment_approved == 'spam' ) {
631 return ;
632 }
633 if ( $comment->comment_type == 'trackback' || $comment->comment_type == 'pingback' ) {
634 return ;
635 }
636 $post_id = $comment->comment_post_ID;
637 $post = get_post( $post_id );
638 if ( $post->post_author == $comment->user_id ) {
639 return ;
640 }
641 if ( ! user_can( $post->post_author, 'moderate_comments' ) && $comment->comment_approved == 0 ) {
642 return;
643 }
644 $this->notify( $post->post_author, $comment );
645 }
646 public function comment_status_changed( $comment_id = 0, $comment_status = 0 ) {
647 if ( ! $this->is_bp_active() ) {
648 return ;
649 }
650 $comment = get_comment( $comment_id );
651 if ( empty( $comment ) ) {
652 return ;
653 }
654 if ( $comment->comment_approved == 'spam' || $comment->comment_approve == 'trash' ) {
655 if ( $this->is_notified( $comment_id ) ) {
656 $this->comment_deleted( $comment_id );
657 }
658 return;
659 }
660 if ( $comment->comment_approve == 0 && $this->is_notified( $comment_id ) ) {
661 $this->comment_deleted( $comment_id );
662 return ;
663 }
664 if ( $comment->comment_approve == 1 ) {
665 $post = get_post( $comment->comment_post_ID );
666 if ( get_current_user_id() == $post->post_author ) {
667 if ( $this->is_notified( $comment_id ) ) {
668 $this->comment_deleted ( $comment_id );
669 }
670 return ;
671 } else {
672 $this->notify( $post->post_author, $comment );
673 }
674 }
675 }
676 public function comment_deleted( $comment_id ) {
677 if ( ! $this->is_bp_active() ) {
678 return;
679 }
680 bp_notifications_delete_all_notifications_by_type( $comment_id, $this->id );
681 $this->unmark_notified( $comment_id );
682 }
683 public function format_notifications( $action, $comment_id, $secondary_item_id, $total_items, $format = 'string', $notification_id = 0 ) {
684 $bp = buddypress();
685 $switched = false;
686 $blog_id = bp_notifications_get_meta( $notification_id, '_blog_id' );
687 if ( $blog_id && get_current_blog_id() != $blog_id ) {
688 switch_to_blog( $blog_id );
689 $switched = true;
690 }
691 $comment = get_comment( $comment_id );
692 $post = get_post( $comment->comment_post_ID);
693 $link = $text = $name = $post_title = $comment_content ='';
694 if ( $comment->user_id ) {
695 $name = bp_core_get_user_displayname ( $comment->user_id );
696 } else {
697 $name = $comment->comment_author;
698 }
699 $post_type = $post->post_type;
700 $post_title = wp_trim_words( $post->post_title, 12, '...' );
701 $comment_content = wp_trim_words( $comment->comment_content, 12, '...' );
702 $text = sprintf(
703 __( '%s commented on your %s, %s', 'bp-notify-post-author-on-blog-comment' ),
704 $name,
705 $post_type,
706 $post_title
707 );
708 if ( $comment->comment_approved == 1 ) {
709 $link = get_comment_link ( $comment );
710 } else {
711 $link =admin_url( 'comment.php?action=approve&c=' . $comment_id );
712 }
713 if( $switched ) {
714 restore_current_blog();
715 }
716 if ( $format == 'string' ) {
717 return apply_filters( 'bp_blog_notieifier_new_comment_notification_string', '<a href="' . $link . '">' . $text . '</a>' );
718 }else{
719 return array(
720 'link' => $link,
721 'text' => $text);
722 }
723 return false;
724 }
725 public function is_bp_active() {
726 if ( function_exists( 'buddypress' ) ) {
727 return true;
728 }
729 return false;
730 }
731 public function is_notified( $comment_id ) {
732 return get_comment_meta( $comment_id, 'bd_post_author_notified', true );
733 }
734 public function mark_notified( $comment_id ) {
735 update_comment_meta( $comment_id, 'bd_post_author_notified', 1 );
736 }
737 public function unmark_notified( $comment_id ) {
738 delete_comment_meta( $comment_id, 'bd_post_author_notified' );
739 }
740 public function notify( $user_id, $comment ) {
741 $comment_id = $comment->comment_ID;
742 $notificatin_id = bp_notifications_add_notification( array(
743 'item_id' => $comment_id,
744 'user_id' => $user_id,
745 'component_name' => $this->id,
746 'component_action' => 'new_blog_comment_'. $comment_id,
747 'secondary_item_id' => $comment->comment_post_ID,
748 ));
749 if ( $notificatin_id && is_multisite() ) {
750 bp_notifications_add_meta( $notificatin_id, '_blog_id', get_current_blog_id() );
751 }
752 $this->mark_notified( $comment_id );
753 }
754 public function mark_read() {
755 if ( ! $this->is_bp_active() || ! is_singular() ) {
756 return ;
757 }
758 $post_id = get_queried_object_id();
759 if ( ! $post_id ) {
760 return ;
761 }
762 return BP_Notifications_Notification::update(
763 array( 'is_new' => 0 ),
764 array( 'secondary_item_id' => $post_id,
765 'component_name' => $this->id,
766 'user_id' => get_current_user_id(),
767 )
768 );
769 }
770}
771BDBP_Blog_Comment_Notifier::get_instance();
772
773
774function millionairesdigest_remove_add_friend_button( $button ) {
775 if ( is_super_admin() ) {
776 return $button;
777 }
778 $displayed_user_id = bp_displayed_user_id();
779 $user_id = ( $displayed_user_id ) ? $displayed_user_id : bp_get_member_user_id();
780 $member_type = bp_get_member_type( $user_id );
781 //Remove the Button for the Following Users with the Displayed Member Type; Show for Everyone Else
782 $in = array( 'brand', 'famous-person', 'organization', 'government' );
783 if ( ! in_array( $member_type, $in, false ) ) {
784 return $button;
785 }
786 return '';
787}
788add_filter('bp_get_add_friend_button', 'millionairesdigest_remove_add_friend_button');
789
790
791/* Permanently Remove the Profile Nav Tab "Friends" from all of the Displayed Users with the Following Member Types "Brand," "Famous Person," "Organization," and "Government" as It Doesn't Make Sense to Our Users, Them, and Us to Have the Ability to Have Friend Lists on Our Platform And Note: This Also Works for When Users are Logged-In too Because Since They Would Be Considered Looking at Their Own Account, It Takes the BuddyPress Displayed User ID Function As if They We're Someone Else Looking At Their Own Profile */
792function millionairesdigest_remove_friends_nav_tab( $tab ) {
793 if ( is_super_admin() && bp_is_my_profile() ) {
794 return;
795 }
796 $displayed_user_id = bp_displayed_user_id();
797 $user_id = ( $displayed_user_id ) ? $displayed_user_id : bp_get_member_user_id();
798 $member_type = bp_get_member_type( $user_id );
799 //Remove the Subnav Tab for the Following Users with the Displayed Member Type
800 $in = array( 'brand', 'famous-person', 'organization', 'government' );
801 if ( ! in_array( $member_type, $in, false ) ) {
802 return $tab;
803 }
804 bp_core_remove_nav_item( 'friends' );
805}
806add_action( 'bp_setup_nav', 'millionairesdigest_remove_friends_nav_tab' );
807
808
809/* Allow All of the Displayed Users with the Following Member Types "Brand," "Famous Person," "Organization," "Millionaire's Digest," and "Government" to Have the "Follow" Button, and Permanently Remove It for Everyone Else And Note: This Also Works for When Users are Logged-In too Because Since They Would Be Considered Looking at Their Own Account, It Takes the BuddyPress Displayed User ID Function As if They We're Someone Else Looking At Their Own Profile */
810function millionairesdigest_allow_follow_button( $button ) {
811 $displayed_user_id = bp_displayed_user_id();
812 $user_id = ( $displayed_user_id ) ? $displayed_user_id : bp_get_member_user_id();
813 $member_type = bp_get_member_type( $user_id );
814 //Allow the Nav Tab for the Following Users with the Displayed Member Type to Be Displayed
815 $in = array( 'brand', 'famous-person', 'organization', 'millionaires-digest', 'government' );
816 if ( ! in_array( $member_type, $in, false ) ) {
817 return '';
818 }
819 return $button;
820}
821add_filter('bp_follow_get_add_follow_button', 'millionairesdigest_allow_follow_button');
822
823
824/* Remove the Profile Subnav Tab "Mutual Friends" for All of the Following Displayed Users Who Have the Member Type "Brand," "Famous Person," "Organization," or "Government" Whenever Someone is On or Viewing Their Profile so that the "Mutual Friends" Subnav Tab Does Not Show */
825function millionairesdigest_remove_mutual_friends_subnav_tab( $tab ) {
826 $displayed_user_id = bp_displayed_user_id();
827 $user_id = ( $displayed_user_id ) ? $displayed_user_id : bp_get_member_user_id();
828 $member_type = bp_get_member_type( $user_id );
829 //Remove the Subnav Tab for the Following Users with the Displayed Member Type
830 $in = array( 'brand', 'famous-person', 'organization', 'government' );
831 if ( ! in_array( $member_type, $in, false ) ) {
832 return $tab;
833 }
834 bp_core_remove_subnav_item( 'friends', 'mutual-friends' );
835}
836add_action( 'bp_setup_nav', 'millionairesdigest_remove_mutual_friends_subnav_tab' );
837
838
839/* Remove the Profile Subnav Tab "Mutual Friends" for All of the Following Logged-In Users Who Have the Member Type "Brand," "Famous Person," "Organization," or "Government" Whenever They are On or Viewing a User's (or Anybody's) Profile, the "Mutual Friends" Tab Does Not Show */
840function millionairedigest_remove_mutual_friends_subnav_tab( $tab ) {
841 if ( is_super_admin() ) {
842 return;
843 }
844 $loggedin_user_id = bp_loggedin_user_id();
845 $user_id = ( $loggedin_user_id ) ? $loggedin_user_id : bp_get_member_user_id();
846 $member_type = bp_get_member_type( $user_id );
847 //Remove the Subnav Tab for the Following Logged-In Users with the Following Member Type
848 $in = array( 'brand', 'famous-person', 'organization', 'government' );
849 if ( ! in_array( $member_type, $in, false ) ) {
850 return $tab;
851 }
852 bp_core_remove_subnav_item( 'friends', 'mutual-friends' );
853}
854add_action( 'bp_setup_nav', 'millionairedigest_remove_mutual_friends_subnav_tab' );
855
856
857/* Adjust the Top Margin for the Profile Subnav Tabs if a Logged-In User is Not Looking at His or Her Profile ONLY as the Subnav Menu Causes Duplicates to Be Displayed. */
858function millionairesdigest_buddypress_profile_subnav_menu() {
859 if( bp_is_my_profile() && bp_is_friends_component() )
860 return false;
861 else
862 if( bp_is_user() && bp_is_friends_component() ) { ?>
863 <style>
864 #subnav.item-list-tabs.no-ajax {
865 margin-top: -10px !important;
866 }
867 </style>
868 <?php
869 }
870}
871add_action('wp_head', 'millionairesdigest_buddypress_profile_subnav_menu');
872
873
874/* Allow All of the Displayed Users with the Following Member Types "Brand," "Famous Person," "Organization," "Millionaire's Digest," and "Government" to Have the Profile Nav Tab "Followers" and "Events," and Permanently Remove It for Everyone Else And Note: This Also Works for When Users are Logged-In too Because Since They Would Be Considered Looking at Their Own Account, It Takes the BuddyPress Displayed User ID Function As if They We're Someone Else Looking At Their Own Profile */
875function millionairesdigest_allow_followers_nav_tab( $tab ) {
876 $displayed_user_id = bp_displayed_user_id();
877 $user_id = ( $displayed_user_id ) ? $displayed_user_id : bp_get_member_user_id();
878 $member_type = bp_get_member_type( $user_id );
879 //Allow the Nav Tab for the Following Users with the Displayed Member Type to Be Displayed
880 $in = array( 'brand', 'famous-person', 'organization', 'millionaires-digest', 'government' );
881 if ( ! in_array( $member_type, $in, false ) ) {
882 bp_core_remove_nav_item( 'added-by' );
883 bp_core_remove_nav_item( 'events' );
884 }
885 return $tab;
886}
887add_action( 'bp_setup_nav', 'millionairesdigest_allow_followers_nav_tab' );
888
889
890/* Hide All of the Following Profile Nav Tabs on ALL User's Profiles As They Are Not Necessary, and So That It is Less Confusing to All of Our Users as We Give Them the Ability to Access Them in Other Places */
891function millionairesdigest_hide_profile_nav_tabs() {
892 global $bp;
893 if ( bp_is_user() && !is_super_admin() ) {
894 unset($bp->bp_nav['private']);
895 unset($bp->bp_nav['contact']);
896 unset($bp->bp_options_nav['activity']['news-feed']);
897 unset($bp->bp_options_nav['activity']['activity-following']);
898 }
899}
900add_action('bp_setup_nav', 'millionairesdigest_hide_profile_nav_tabs', 201);
901
902
903/* 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! ) */
904//Add the "Matchmaker Bio" Profile Field to the Member Directoy
905function my_directory() {
906if ( bp_is_active( 'xprofile' ) )
907 if ( $matchmaker_bio = xprofile_get_field_data( 'Matchmaker Bio', bp_get_member_user_id() ) ) :
908 echo '<div class="Matchmaker_Bio">';
909 echo $matchmaker_bio;
910 echo '</div>';
911 endif;
912}
913add_filter( 'bp_directory_members_item', 'my_directory' );
914
915
916/* Add the shortcode to display the logged-in user's role */
917function kleo_bp_member_type_label() {
918 $displayed_user_id = bp_displayed_user_id();
919 $member_type = bp_get_member_type( bp_get_member_user_id() );
920 if ( empty( $member_type ) ) {
921 return;
922 }
923 $member_type_object = bp_get_member_type_object( $member_type );
924 if($member_type_object){
925 $member_type_label = '<p class="kleo_bp_profile_member_type_label">' . esc_html( $member_type_object->labels['singular_name'] ) . '</p>';
926 echo apply_filters('kleo_bp_profile_member_type_label', $member_type_label);
927 }
928}
929add_action( 'bp_actions', 'kleo_bp_member_type_label' );
930if ( ! function_exists( 'ks_shortcode' ) ) {
931 function ks_shortcode() {
932 return kleo_bp_member_type_label();
933 }
934 add_shortcode( 'kleo_member_type', 'ks_shortcode' );
935}
936
937
938/* 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. */
939function millionairesdigest_redirect_on_first_login( $url, $request, $user ) {
940 $last_activity = bp_get_user_last_activity( $user->ID );
941 if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
942 if( $user->has_cap( 'user' ) && empty( $last_activity ) ) {
943 $url = home_url('/welcome/users/');
944 } else {
945 if( $user->has_cap( 'brand-account' ) && empty( $last_activity ) ) {
946 $url = home_url('/welcome/brands/');
947 } else {
948 if( $user->has_cap( 'famous-person-account' ) && empty( $last_activity ) ) {
949 $url = home_url('/welcome/famous-people/');
950 } else {
951 if( $user->has_cap( 'organization-account' ) && empty( $last_activity ) ) {
952 $url = home_url('/welcome/organizations/');
953 } else {
954 if( $user->has_cap( 'government-account' ) && empty( $last_activity ) ) {
955 $url = home_url('/welcome/government/');
956 } else {
957 if( $user->has_cap( 'contributor' ) && empty( $last_activity ) ) {
958 $url = home_url('/welcome/contributors/');
959 } else {
960 if( $user->has_cap( 'photographer' ) && empty( $last_activity ) ) {
961 $url = home_url('/welcome/photographers/');
962 } else {
963 if( $user->has_cap( 'author' ) && empty( $last_activity ) ) {
964 $url = home_url('/welcome/authors/');
965 } else {
966 if( $user->has_cap( 'editor' ) && empty( $last_activity ) ) {
967 $url = home_url('/welcome/editors/');
968 } else {
969 if( $user->has_cap( 'publisher' ) && empty( $last_activity ) ) {
970 $url = home_url('/welcome/publishers/');
971 } else {
972 if( $user->has_cap( 'magazine-author' ) && empty( $last_activity ) ) {
973 $url = home_url('/welcome/magazine-authors/');
974 } else {
975 if( $user->has_cap( 'magazine-photographer' ) && empty( $last_activity ) ) {
976 $url = home_url('/welcome/magazine-photographers/');
977 } else {
978 if( $user->has_cap( 'magazine-editor' ) && empty( $last_activity ) ) {
979 $url = home_url('/welcome/users/');
980 } else {
981 if( $user->has_cap( 'magazine-designer' ) && empty( $last_activity ) ) {
982 $url = home_url('/welcome/magazine-designers/');
983 } else {
984 if( $user->has_cap( 'magazine-publisher' ) && empty( $last_activity ) ) {
985 $url = home_url('/welcome/magazine-publishers/');
986 } else {
987 $url = home_url('/activity-wall/');
988 }
989 }
990 }
991 }
992 }
993 }
994 }
995 }
996 }
997 }
998 }
999 }
1000 }
1001 }
1002 }
1003 }
1004 return $url;
1005}
1006add_filter('login_redirect', 'millionairesdigest_redirect_on_first_login', 10, 3 );
1007
1008
1009/* 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) */
1010add_action( 'wp_logout', create_function( '', 'wp_redirect( home_url() ); exit();' ) );
1011
1012
1013/* 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 */
1014function set_default_member_type( $user_id, $user_login, $user_password, $user_email, $usermeta ) {
1015 bp_set_member_type( $user_id, 'user' );
1016}
1017add_action( 'bp_core_signup_user', 'set_default_member_type', 10, 5 );
1018
1019
1020/* Auto Join All New Team & Company Members to Groups Based on Their Role After Creating Their Account and Logging in for the First Time */
1021function auto_join_contributors_to_groups( $user_id, $role, $old_roles ) {
1022 if( $role == 'contributor' ) {
1023 groups_accept_invite( $user_id, 1 );
1024 groups_accept_invite( $user_id, 11 );
1025 groups_accept_invite( $user_id, 13 );
1026 }
1027}
1028add_action( 'set_user_role', 'auto_join_contributors_to_groups', 11, 3 );
1029function auto_join_photographers_to_groups( $user_id, $role, $old_roles ) {
1030 if( $role == 'photographer' ) {
1031 groups_accept_invite( $user_id, 2 );
1032 groups_accept_invite( $user_id, 11 );
1033 groups_accept_invite( $user_id, 13 );
1034 }
1035}
1036add_action( 'set_user_role', 'auto_join_photographers_to_groups', 11, 3 );
1037function auto_join_authors_to_groups( $user_id, $role, $old_roles ) {
1038 if( $role == 'author' ) {
1039 groups_accept_invite( $user_id, 3 );
1040 groups_accept_invite( $user_id, 11 );
1041 groups_accept_invite( $user_id, 13 );
1042 }
1043}
1044add_action( 'set_user_role', 'auto_join_authors_to_groups', 11, 3 );
1045function auto_join_editors_to_groups( $user_id, $role, $old_roles ) {
1046 if( $role == 'editor' ) {
1047 groups_accept_invite( $user_id, 4 );
1048 groups_accept_invite( $user_id, 11 );
1049 groups_accept_invite( $user_id, 13 );
1050 }
1051}
1052add_action( 'set_user_role', 'auto_join_editors_to_groups', 11, 3 );
1053function auto_join_publishers_to_groups( $user_id, $role, $old_roles ) {
1054 if( $role == 'publisher' ) {
1055 groups_accept_invite( $user_id, 5 );
1056 groups_accept_invite( $user_id, 11 );
1057 groups_accept_invite( $user_id, 13 );
1058 }
1059}
1060add_action( 'set_user_role', 'auto_join_publishers_to_groups', 11, 3 );
1061function auto_join_magazine_authors_to_groups( $user_id, $role, $old_roles ) {
1062 if( $role == 'magazine-author' ) {
1063 groups_accept_invite( $user_id, 6 );
1064 groups_accept_invite( $user_id, 12 );
1065 groups_accept_invite( $user_id, 13 );
1066 }
1067}
1068add_action( 'set_user_role', 'auto_join_magazine_authors_to_groups', 11, 3 );
1069function auto_join_magazine_photographers_to_groups( $user_id, $role, $old_roles ) {
1070 if( $role == 'magazine-photographer' ) {
1071 groups_accept_invite( $user_id, 7 );
1072 groups_accept_invite( $user_id, 12 );
1073 groups_accept_invite( $user_id, 13 );
1074 }
1075}
1076add_action( 'set_user_role', 'auto_join_magazine_photographers_to_groups', 11, 3 );
1077function auto_join_magazine_editors_to_groups( $user_id, $role, $old_roles ) {
1078 if( $role == 'magazine-editor' ) {
1079 groups_accept_invite( $user_id, 8 );
1080 groups_accept_invite( $user_id, 12 );
1081 groups_accept_invite( $user_id, 13 );
1082 }
1083}
1084add_action( 'set_user_role', 'auto_join_magazine_editors_to_groups', 11, 3 );
1085function auto_join_magazine_designers_to_groups( $user_id, $role, $old_roles ) {
1086 if( $role == 'magazine-designer' ) {
1087 groups_accept_invite( $user_id, 9 );
1088 groups_accept_invite( $user_id, 12 );
1089 groups_accept_invite( $user_id, 13 );
1090 }
1091}
1092add_action( 'set_user_role', 'auto_join_magazine_designers_to_groups', 11, 3 );
1093function auto_join_magazine_publishers_to_groups( $user_id, $role, $old_roles ) {
1094 if( $role == 'magazine-publisher' ) {
1095 groups_accept_invite( $user_id, 10 );
1096 groups_accept_invite( $user_id, 12 );
1097 groups_accept_invite( $user_id, 13 );
1098 }
1099}
1100add_action( 'set_user_role', 'auto_join_magazine_publishers_to_groups', 11, 3 );
1101
1102
1103/* Redirect Any and All Logged Out Users Who Try to Access the Member Directory Page to the Homepage as the Memeber Directory Isn't Something That People Should Be Able to Access Freely Because It Gives People the Ability to See Eveyone and Eveything When the Point of the Member Directory is to Give People the Power to Find Friends & Matches Based on Their Pofile */
1104function bpfr_guest_redirect() {
1105 global $bp;
1106 // Enter the slug or component conditional here
1107 if ( bp_is_members_directory() ) {
1108 // Not logged in user are redirected to - comment/uncomment or add/remove to your need
1109 if( !is_user_logged_in() ) {
1110 wp_redirect( get_option('siteurl') ); //back to homepage
1111 }
1112 }
1113}
1114add_filter( 'get_header', 'bpfr_guest_redirect', 1 );
1115
1116
1117/* Remove the "Sent" Messages Subnav Tab in Users Profiles as It is Not Neccessary and Helps Keep the Inbox More Clear for Our Users */
1118function md_remove_sent_messages_subnav_tab() {
1119 if ( is_super_admin() ) {
1120 return;
1121 }
1122 global $bp;
1123 if ( $bp->current_component == $bp->messages->slug ) {
1124 bp_core_remove_subnav_item( $bp->messages->slug, 'sentbox' );
1125 }
1126}
1127add_action( 'wp', 'md_remove_sent_messages_subnav_tab', 2 );
1128
1129
1130/* Hide the Featured Image on Single Custom Post Type "Videos" as the Featured Image Causes a Duplicate View of the Set Video Image */
1131function millionairesdigest_featured_image() {
1132 if( is_single() && get_post_type() == 'video' ) { ?>
1133 <style>
1134 .has-post-thumbnail img.wp-post-image {
1135 display: none;
1136 }
1137 </style>
1138 <?php
1139 }
1140}
1141add_action('wp_head', 'millionairesdigest_featured_image');
1142
1143
1144/* Remove/Hide Some of the Page Elements from the "Blocked" Template found in the Millionaire's Digest Block Plugin as the Current Template Does Not Completely Show the Main Theme's 404 Error Page Correctly */
1145function millionairesdigest_blocked_user_template() {
1146 if( bp_is_current_component( 'blocked' ) ) {?>
1147 <style>
1148 .page-title {
1149 display: none !important;
1150 }
1151 .template-page {
1152 border: none !important;
1153 position: inherit !important;
1154 width: 100% !important;
1155 }
1156 </style>
1157 <?php
1158 }
1159 }
1160add_action('wp_head', 'millionairesdigest_blocked_user_template');
1161
1162
1163/* Add Support for Allowing Us to Display the Logged-In User's Role. And Note: Keep In Mind that Because Some Writers and Photographers Apply to Be a Part for Both the Platform and Magazine, the Shortcode Only Allows Us to Show Only One of Their Roles Instead of Both of Them, and How That Role is Determined Depends on the First Role We Initially Assign to Them, so if Someone Applies to Be a Writer or a Photographer for Both the Platform and Magazine, Always Assign the Platform Role to Them First Since that Role Always Uses the Main Singular Name */
1164function get_user_role( $role_name ) {
1165 global $current_user;
1166 $user = 'User';
1167 $subscriber = 'Subscriber';
1168 $customer = 'Customer';
1169 $brand_account = 'Brand Account';
1170 $famous_person_account = 'Famous Person';
1171 $organization_account = 'Organization Account';
1172 $government_account = 'Government Account';
1173 $contributor = 'Writer';
1174 $photographer = 'Photographer';
1175 $author = 'VIP Writer';
1176 $editor = 'Editor';
1177 $publisher = 'Publisher';
1178 $magazine_author = 'Magazine Writer';
1179 $magazine_photographer = 'Magazine Photographer';
1180 $magazine_editor = 'Magazine Editor';
1181 $magazine_designer = 'Magazine Designer';
1182 $magazine_publisher = 'Magazine Publisher';
1183 $administrator = 'Founder';
1184 if ( ! $role_name )
1185 $role_name = $current_user->ID;
1186 if ( is_user_logged_in() ) {
1187 $user_role = new WP_User( $role_name );
1188 if ( !empty( $user_role->roles ) && is_array( $user_role->roles ) ) {
1189 foreach ( $user_role->roles as $role )
1190 if ( $role == 'user' ) {
1191 return $user;
1192 } else if
1193 ( $role == 'subscriber' ) {
1194 return $subscriber;
1195 } else if
1196 ( $role == 'customer' ) {
1197 return $customer;
1198 } else if
1199 ( $role == 'brand-account' ) {
1200 return $brand_account;
1201 } else if
1202 ( $role == 'famous-person-account' ) {
1203 return $famous_person_account;
1204 } else if
1205 ( $role == 'organization-account' ) {
1206 return $organization_account;
1207 } else if
1208 ( $role == 'government-account' ) {
1209 return $government_account;
1210 } else if
1211 ( $role == 'contributor' ) {
1212 return $contributor;
1213 } else if
1214 ( $role == 'photographer' ) {
1215 return $photographer;
1216 } else if
1217 ( $role == 'author' ) {
1218 return $author;
1219 } else if
1220 ( $role == 'editor' ) {
1221 return $editor;
1222 } else if
1223 ( $role == 'publisher' ) {
1224 return $publisher;
1225 } else if
1226 ( $role == 'magazine-author' ) {
1227 return $magazine_author;
1228 } else if
1229 ( $role == 'magazine-photographer' ) {
1230 return $magazine_photographer;
1231 } else if
1232 ( $role == 'magazine-editor' ) {
1233 return $magazine_editor;
1234 } else if
1235 ( $role == 'magazine-designer' ) {
1236 return $magazine_designer;
1237 } else if
1238 ( $role == 'magazine-publisher' ) {
1239 return $magazine_publisher;
1240 } else if
1241 ( $role == 'administrator' ) {
1242 return $administrator;
1243 }
1244 return;
1245 }
1246 }
1247}
1248//Add the shortcode to display the logged-in user's role
1249if ( ! function_exists( 'kk_shortcode' ) ) {
1250 function kk_shortcode() {
1251 return get_user_role( $role_name );
1252 }
1253 add_shortcode( 'display_user_role', 'kk_shortcode' );
1254}
1255
1256
1257/* Add a "Logged-In Users Only" Metabox to Pages and Post Types on the Backend Dashboard for the Purpose of Allowing Us to Make Pages and Post Types Visible and Accessbile to Users Who are Logged In, and That Shouldn't Be Able to Be Accessed Without Users Being Logged-In */
1258function pp_private_add_meta_box() {
1259 $args = array(
1260 'public' => true,
1261 );
1262 $output = 'names';
1263 $post_types = get_post_types( $args, $output );
1264 $pp_private_cpts = array( 'post','article','video','photo','audio','page','company', array() );
1265 foreach ( $post_types as $post_type ) {
1266 if ( ! in_array( $post_type, $skip_these_bbPress ) ) {
1267 if ( in_array( $post_type, $pp_private_cpts ) ) {
1268 add_meta_box(
1269 'pp_private_sectionid',
1270 __( 'Logged-In Users Only', 'bp-simple-private' ),
1271 'pp_private_meta_box_callback',
1272 $post_type,
1273 'side',
1274 'high'
1275 );
1276 }
1277 }
1278 }
1279}
1280add_action( 'add_meta_boxes', 'pp_private_add_meta_box' );
1281// Print the box content
1282function pp_private_meta_box_callback( $post ) {
1283 $front_id = get_option('page_on_front');
1284 if ( $post->ID == $front_id )
1285 _e( 'This is your Front Page - and cannot be Private.', 'bp-simple-private' );
1286 else {
1287 wp_nonce_field( 'pp_private_save_meta_box_data', 'pp_private_meta_box_nonce' );
1288 $value = get_post_meta( $post->ID, 'pp-private', true );
1289 ?>
1290 <input type="checkbox" id="pp-private" name="pp-private" value="1" <?php checked( $value, 1 ); ?> />
1291 <label for="pp_private">
1292 <?php _e( 'Yes - This post or page is available to logged-in users only', 'bp-simple-private' ); ?>
1293 </label>
1294<?php
1295 }
1296}
1297//Save or delete meta box data when the post is saved or updated
1298function pp_private_save_meta_box_data( $post_id ) {
1299 if ( ! isset( $_POST['pp_private_meta_box_nonce'] ) )
1300 return;
1301 if ( ! wp_verify_nonce( $_POST['pp_private_meta_box_nonce'], 'pp_private_save_meta_box_data' ) )
1302 return;
1303 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
1304 return;
1305 // check user permissions
1306 if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {
1307 if ( ! current_user_can( 'manage_options', $post_id ) )
1308 return;
1309 }
1310 else {
1311 if ( ! current_user_can( 'manage_options', $post_id ) )
1312 return;
1313 }
1314 // update or delete the post_meta
1315 if ( ! isset( $_POST['pp-private'] ) )
1316 delete_post_meta($post_id, 'pp-private', '');
1317 else {
1318 $front_id = get_option('page_on_front');
1319 if ( $post_id != $front_id ) {
1320 $private_data = sanitize_text_field( $_POST['pp-private'] );
1321 update_post_meta( $post_id, 'pp-private', $private_data );
1322 }
1323 else
1324 delete_post_meta($post_id, 'pp-private', '');
1325 }
1326}
1327add_action( 'save_post', 'pp_private_save_meta_box_data' );
1328//Add the metabox
1329function pp_private_check() {
1330 global $wp;
1331 if ( ! is_admin() && ! is_user_logged_in() ) {
1332 if ( is_front_page() || is_home() || bp_is_register_page() || bp_is_activation_page() )
1333 return;
1334 $redirect_url = trailingslashit( site_url() );
1335 $pp_private_components = get_option( 'pp-private-components' );
1336 if ( $pp_private_components == false )
1337 $pp_private_components = array();
1338 if ( bp_is_user() && in_array( 'member Profile Pages', $pp_private_components ) )
1339 bp_core_redirect( $redirect_url );
1340 $bp_current_component = bp_current_component();
1341 if ( false != $bp_current_component ) {
1342 if ( in_array( $bp_current_component, $pp_private_components ) )
1343 bp_core_redirect( $redirect_url );
1344 }
1345 if ( is_single() || is_page() ) {
1346 $pp_private_cpts = get_option( 'pp-private-cpts' );
1347 if ( $pp_private_cpts == false )
1348 $pp_private_cpts = array();
1349 $post_type = get_post_type( get_the_ID() );
1350 if ( in_array( $post_type, $pp_private_cpts ) ) {
1351 $pp_private = get_post_meta( get_the_ID(), 'pp-private', true );
1352 if ( $pp_private == '1' )
1353 bp_core_redirect( $redirect_url );
1354 }
1355 }
1356 }
1357}
1358add_action( 'bp_ready', 'pp_private_check' );
1359
1360
1361/* Hide the Footer for Any and All Logged-In Users Since the Footer isn't Really Helpful for Them as It's Only Used for Displaying Information and Things to Logged Out Users and First Time Visitors */
1362function millionairesdigest_footer() {
1363 if( is_user_logged_in() ) { ?>
1364 <style>
1365 .footer-color#footer {
1366 display: none;
1367 }
1368 .socket-color {
1369 background-color: #ffffff !important;
1370 color: #777777 !important;
1371 }
1372 }
1373 </style>
1374 <?php
1375 }
1376}
1377add_action('wp_head', 'millionairesdigest_footer');
1378
1379
1380/* Add a Shortcode ([bp-pm-button username=optional_some_user_name]) for Allowing Us to Display the "Private Message CEO" Button on All Our Dashboard Pages for the Purpose of Making It Easier on All Our Writers, Authors, Photogaphers, Etc. So That When They Click on the Button, They Do Not have to Manually Put in Our Name as It Will Automatically Do It for Them */
1381function millionairesdigest_get_send_private_message_to_user_url( $user_id ) {
1382 return wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r=' . bp_core_get_username( $user_id ) );
1383}
1384function millionairesdigest_private_message_button_shortcode( $atts, $content = '' ) {
1385 if ( ! is_user_logged_in() ) {
1386 return '';
1387 }
1388 $atts = shortcode_atts( array(
1389 'user_id' => '',
1390 'username' => '',
1391 'label' => 'Message CEO',
1392 ), $atts );
1393 $user_id = absint( $atts['user_id'] );
1394 $user_login = $atts['username'];
1395 // If the username is given, override the user id.
1396 if ( $user_login ) {
1397 $user = get_user_by( 'login', $user_login );
1398 if ( ! $user ) {
1399 return '';
1400 }
1401 $user_id = $user->ID;
1402 }
1403 if ( ! $user_id ) {
1404 if ( ! in_the_loop() ) {
1405 return '';
1406 }
1407 $user_id = get_the_author_meta('ID' );
1408 }
1409 // If we are here, generate the button.
1410 $button = sprintf('<a href="%1$s">%2$s</a>', millionairesdigest_get_send_private_message_to_user_url( $user_id ), $atts['label'] );
1411 return $button . $content;
1412}
1413add_shortcode( 'bp-pm-button', 'millionairesdigest_private_message_button_shortcode' );
1414
1415
1416/* Add a Shortcode for Allowing Us to Display the BuddyPress Follow Button */
1417function millionairesdigest_follow_add_follow_button( $args = '' ) {
1418 echo millionairesdigest_follow_get_add_follow_button( $args );
1419}
1420function millionairesdigest_follow_get_add_follow_button( $args = '' ) {
1421 global $bp, $members_template;
1422 $r = wp_parse_args( $args, array(
1423 'leader_id' => get_the_author_meta( 'ID' ),
1424 'follower_id' => bp_loggedin_user_id(),
1425 'link_text' => '',
1426 'link_title' => '',
1427 'wrapper_class' => '',
1428 'link_class' => '',
1429 'wrapper' => 'div'
1430 ) );
1431
1432 if ( ! $r['leader_id'] || ! $r['follower_id'] )
1433 return false;
1434 $loggedin_user_id = get_the_author_meta('ID' );
1435 if ( bp_loggedin_user_id() === $loggedin_user_id ) {
1436 return '';
1437 }
1438
1439 //If we're checking during a members loop, then follow status is already. Queried via bp_follow_inject_member_follow_status()
1440 if ( ! empty( $members_template->in_the_loop ) && $r['follower_id'] == bp_loggedin_user_id() && $r['leader_id'] == bp_get_member_user_id() ) {
1441 $is_following = $members_template->member->is_following;
1442 //Else we manually query the follow status
1443 } else {
1444 $is_following = bp_follow_is_following( array(
1445 'leader_id' => $r['leader_id'],
1446 'follower_id' => $r['follower_id']
1447 ) );
1448 }
1449
1450 //If the logged-in user is the leader, use already-queried variables
1451 if ( bp_loggedin_user_id() && $r['leader_id'] == bp_loggedin_user_id() ) {
1452 $leader_domain = bp_loggedin_user_domain();
1453 $leader_fullname = bp_get_loggedin_user_fullname();
1454 // else we do a lookup for the user domain and display name of the leader
1455 } else {
1456 $leader_domain = bp_core_get_user_domain( $r['leader_id'] );
1457 $leader_fullname = bp_core_get_user_displayname( $r['leader_id'] );
1458 }
1459
1460 //Setup some variables
1461 if ( $is_following ) {
1462 $id = 'following';
1463 $action = 'stop';
1464 $class = 'unfollow';
1465 $link_text = sprintf( _x( 'Unadd Account', 'Button', 'bp-follow' ), apply_filters( 'bp_follow_leader_name', bp_get_user_firstname( $leader_fullname ), $r['leader_id'] ) );
1466 if ( empty( $r['link_text'] ) ) {
1467 $r['link_text'] = $link_text;
1468 }
1469 } else {
1470 $id = 'not-following';
1471 $action = 'start';
1472 $class = 'follow';
1473 $link_text = sprintf( _x( 'Add Account', 'Button', 'bp-follow' ), apply_filters( 'bp_follow_leader_name', bp_get_user_firstname( $leader_fullname ), $r['leader_id'] ) );
1474 if ( empty( $r['link_text'] ) ) {
1475 $r['link_text'] = $link_text;
1476 }
1477 }
1478 $wrapper_class = 'follow-button ' . $id;
1479 if ( ! empty( $r['wrapper_class'] ) ) {
1480 $wrapper_class .= ' ' . esc_attr( $r['wrapper_class'] );
1481 }
1482 $link_class = $class;
1483 if ( ! empty( $r['link_class'] ) ) {
1484 $link_class .= ' ' . esc_attr( $r['link_class'] );
1485 }
1486
1487 //Make sure we can view the button if a user is on their own page
1488 $block_self = empty( $members_template->member ) ? true : false;
1489 //If we're using AJAX and a user is on their own profile, we need to set. Block_self to false so the button shows up
1490 if ( ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( $_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ) && bp_is_my_profile() ) {
1491 $block_self = false;
1492 }
1493
1494 //Setup the button arguments
1495 $button = array(
1496 'id' => $id,
1497 'component' => 'follow',
1498 'must_be_logged_in' => true,
1499 'block_self' => $block_self,
1500 'wrapper_class' => $wrapper_class,
1501 'wrapper_id' => 'follow-button-' . (int) $r['leader_id'],
1502 'link_href' => wp_nonce_url( $leader_domain . $bp->follow->followers->slug . '/' . $action .'/', $action . '_following' ),
1503 'link_text' => esc_attr( $r['link_text'] ),
1504 'link_title' => esc_attr( $r['link_title'] ),
1505 'link_id' => $class . '-' . (int) $r['leader_id'],
1506 'link_class' => $link_class,
1507 'wrapper' => ! empty( $r['wrapper'] ) ? esc_attr( $r['wrapper'] ) : false
1508 );
1509
1510 //Filter and return the HTML button
1511 return bp_get_button( apply_filters( 'md_follow_get_add_follow_button', $button, $r['leader_id'], $r['follower_id'] ) );
1512}
1513//Create the shortcode to display the follow button
1514if ( ! function_exists( 'kb_shortcode' ) ) {
1515 function kb_shortcode() {
1516 return millionairesdigest_follow_get_add_follow_button( $args );
1517 }
1518 add_shortcode( 'follow_button', 'kb_shortcode' );
1519}
1520
1521
1522/* Change the Word "Buddyblog" on User's Proile Tabs so It Just Returns the Post Type Name in the Links Instead of the "Buddyblog" Word Along with It */
1523define( 'BP_BUDDYBLOGARTICLES_SLUG','articles' );
1524define( 'BP_BUDDYBLOGVIDEOS_SLUG','videos' );
1525define( 'BP_BUDDYBLOGPHOTOS_SLUG','photos' );
1526define( 'BP_BUDDYBLOGMUSIC_SLUG','music' );
1527
1528
1529/* Remove the Following BuddyBlog Subnav Tabs as They Are Not Necessary and We Do Not Need Them Because Users Do Not Use Them */
1530function bpfr_hide_tabs() {
1531 global $bp;
1532 if ( bp_is_user() && !is_super_admin() ) {
1533 bp_core_remove_subnav_item( 'articles', 'edit' );
1534 bp_core_remove_subnav_item( 'videos', 'edit' );
1535 bp_core_remove_subnav_item( 'photos', 'edit' );
1536 bp_core_remove_subnav_item( 'music', 'edit' );
1537 }
1538}
1539add_action( 'bp_setup_nav', 'bpfr_hide_tabs', 15 );
1540
1541
1542/* Hide the Following BuddyPress Profile Nav Tabs and rtMedia Upload Link on All of Our Members Profiles as We Give All of Them the Ability to Access Them from Other Places and It's Less Confusing for Them */
1543function millionairesdigest_hide_profile_tabs() {
1544 if ( bp_is_user() && !is_super_admin() ) { ?>
1545 <style>
1546 #user-messages, #user-notifications, #user-orders, #user-settings, #rtm-media-options .rtmedia-upload-media-link {
1547 display: none !important;
1548
1549 }
1550 }
1551 </style>
1552 <?php
1553 }
1554}
1555add_action('wp_head', 'millionairesdigest_hide_profile_tabs');
1556
1557
1558/* Set the Following BuddyPress Profile Fields that Allow Users to Input Links for Other Users to Click On and Visit to Automatically Open Up in a New Tab so That They Do Not Lose Where They Are Currently At On a Page, as Well as Can Easily Pick Back Up Where They Left Off */
1559function millionairesdigest_field_links( $field_link, $field_type, $field_id ) {
1560 if( $field_id == 3399 || $field_id == 3429 ) {
1561 $field_link = str_replace( 'rel="nofollow"', 'rel="nofollow" target="_blank"', $field_link );
1562 }
1563 return $field_link;
1564}
1565add_filter('bp_get_the_profile_field_value', 'millionairesdigest_field_links', 11, 3);
1566
1567
1568/* Allow Pages with the Post Status "Private" to Be Selected as a Parent Page from the Dropdown Menu on the Backend Dashboard, as Well as for the Purpose of Keeping the Sub-Pages that Fall Under Those Privately Marked Parent Pages as Child Pages Whenever We Have to Use the Backend Dashboard Editor to Update, Fix, or Make Changes to Them */
1569function millionairesdigest_private_pages( $args ) {
1570 $args['post_status'] = array( 'publish', 'private' );
1571 return $args;
1572}
1573add_filter( 'page_attributes_dropdown_pages_args', 'millionairesdigest_private_pages' );
1574add_filter( 'quick_edit_dropdown_pages_args', 'millionairesdigest_private_pages' );
1575
1576
1577/* Hide the Annoying Update Notifications for All of the Following Plugins as I Do Not Plan to Update Them in the Future as They Already Do and Provide the Current Features I Need */
1578function remove_update_notifications( $value ) {
1579 if ( isset( $value ) && is_object( $value ) ) {
1580 unset( $value->response[ 'advanced-custom-fields-pro/acf.php' ] );
1581 unset( $value->response[ 'pages-by-user-role/pages-by-user-role.php' ] );
1582 unset( $value->response[ 'blog-designer-pro/blog-designer-pro.php' ] );
1583 unset( $value->response[ 'wp-upg/wp-upg.php' ] );
1584 unset( $value->response[ 'buddypress-media/index.php' ] );
1585 unset( $value->response[ 'typed/typed.php' ] );
1586 unset( $value->response[ 'user-role-editor-pro/user-role-editor-pro.php' ] );
1587 unset( $value->response[ 'buddypress-follow/loader.php' ] );
1588 unset( $value->response[ 'bp-featured-members/bp-featured-members.php' ] );
1589 }
1590 return $value;
1591}
1592add_filter( 'site_transient_update_plugins', 'remove_update_notifications' );
1593
1594
1595/* Change the Email "From Name" from "WordPress" to "Millionaire's Digest" for the Purpose of Making It Less Confusing to Our Users, and so that Whenever Users Receive any Type of Email (Like Password Resets, BuddyPress Notifications, Contact Forms, Magazine Order Confirmations, Etc.), the Display Name Always Shows It's from Us and Not WordPress */
1596function millionairesdigest_email_name( $original_email_from ) {
1597 $name = 'Millionaire\'s Digest';
1598 return $name;
1599}
1600add_filter( 'wp_mail_from_name', 'millionairesdigest_email_name' );
1601
1602
1603/* Rename the BuddyPress Button Texts for the "Friend Button" */
1604function millionairesdigest_rename_friend_button( $button ) {
1605 if( is_array( $button ) && isset( $button['id'] ) ) {
1606 if( $button['id'] == 'pending' ) {
1607 $button['link_text'] = 'Request Sent';
1608 }
1609 elseif( $button['id'] == 'awaiting_response' ) {
1610 $button['link_text'] = 'Accept Request';
1611 }
1612 elseif( $button['id'] == 'is_friend' ) {
1613 $button['link_text'] = 'Unfriend';
1614 }
1615 elseif( $button['id'] == 'not_friends' ) {
1616 $button['link_text'] = 'Add Friend';
1617 }
1618 }
1619 return $button;
1620}
1621add_filter( 'bp_get_add_friend_button','millionairesdigest_rename_friend_button');
1622
1623
1624/* Allow All of the Displayed Users with the Following Member Types "Brand," "Famous Person," "Organization," "Millionaire's Digest," and "Government" to Have the Profile Nav Tab "Contact Form" and the Profile Subav Tab "Contact Form Settings," and Permanently Remove It for Everyone Else And Note: This Also Works for When Users are Logged-In too Because Since They Would Be Considered Looking at Their Own Account, It Takes the BuddyPress Displayed User ID Function As if They We're Someone Else Looking At Their Own Profile */
1625function millionairesdigest_allow_contact_form_nav_tab( $tab ) {
1626 $displayed_user_id = bp_displayed_user_id();
1627 $user_id = ( $displayed_user_id ) ? $displayed_user_id : bp_get_member_user_id();
1628 $member_type = bp_get_member_type( $user_id );
1629 //Allow the Nav Tab for the Following Users with the Displayed Member Type to Be Displayed
1630 $in = array( 'brand', 'famous-person', 'organization', 'millionaires-digest', 'government' );
1631 if ( ! in_array( $member_type, $in, false ) ) {
1632 bp_core_remove_nav_item( 'contact' );
1633 bp_core_remove_subnav_item( 'settings', 'contact' );
1634 }
1635 return $tab;
1636}
1637add_action( 'bp_setup_nav', 'millionairesdigest_allow_contact_form_nav_tab' );
1638
1639
1640/* Rename the "Added by Me" to "Added by Us" Nav Tab for the Displayed Users with the Following Member Types "Brand," "Organization," and "Government" */
1641function rename_added_by_me_profile_nav_tab( $name ) {
1642 global $bp;
1643 $count = bp_follow_total_follow_counts( array( 'user_id' =>bp_displayed_user_id() ) );
1644 $displayed_user_id = bp_displayed_user_id();
1645 $user_id = ( $displayed_user_id ) ? $displayed_user_id : bp_get_member_user_id();
1646 $member_type = bp_get_member_type( $user_id );
1647 //Allow the Nav Tab for the Following Users with the Displayed Member Type to Be Displayed
1648 $in = array( 'brand', 'organization', 'government' );
1649 if ( ! in_array( $member_type, $in, false ) ) {
1650 return $name;
1651 }
1652 $bp->bp_nav['added']['name'] = sprintf( __( 'Added by Us <span>%d</span>' ), $count['following'] );
1653}
1654add_action('bp_setup_nav', 'rename_added_by_me_profile_nav_tab', 999);
1655
1656
1657/* Set the rtMedia Widget to Display the Displayed User's Uploads or the Displayed Groups Uploads that a User is Currently On or Viewing Instead of All of the Sitewide Public Uploads */
1658function rtm_custom_widget_add_filter_update_where_query() {
1659 add_filter( "rtmedia-model-where-query", 'rtm_custom_widget_function_update_where_query', 20, 2 );
1660}
1661function rtm_custom_widget_function_update_where_query( $where, $table_name ) {
1662 $disp_user = bp_get_current_group_id();
1663 $where .= " AND ( {$table_name}.context = 'group' and {$table_name}.context_id = '".$disp_user."' ) ";
1664 add_action( 'rtmedia_after_gallery_widget_content', 'rtm_custom_widget_remove_filter_update_where_query', 10 );
1665 return $where;
1666}
1667function rtm_custom_widget_remove_filter_update_where_query() {
1668 remove_filter( 'rtmedia-model-where-query', 'rtm_custom_widget_add_filter_update_where_query' );
1669}
1670add_action( 'rtmedia_before_gallery_widget_content','rtm_custom_widget_add_filter_update_where_query', 10 );
1671
1672
1673/* Restrict Access to Certain Parts, Pages, Post Types, Etc. on the Wp-Admin Backend Site Based on Users Roles and Capabilities */
1674//Hide the Following Menu Items from the Wp-Admin Menu
1675function millionairesdigest_hide_admin_menu_items() {
1676 if ( current_user_can( 'edit_others_posts' ) ) {
1677 return;
1678 }
1679 remove_menu_page( 'tools.php' );//Tools
1680 remove_menu_page( 'wpcf7' );//Contact Form 7
1681 remove_menu_page( 'vc-welcome' );//Visual Composer
1682}
1683add_action( 'admin_menu', 'millionairesdigest_hide_admin_menu_items' );
1684//Now, Restrict Access Those Same Following Admin Pages
1685function millionairesdigest_restrict_access_to_admin_pages() {
1686 if ( current_user_can( 'edit_others_posts' ) ) {
1687 return;
1688 }
1689 $current_screen_id = get_current_screen()->id;
1690 $restricted_screen = array(
1691 'tools',
1692 'wpcf7',
1693 );
1694 foreach( $restricted_screen as $restricted_screens ) {
1695 if( $current_screen_id === $restricted_screens ) {
1696 wp_redirect( get_option( 'siteurl' ) . '/wp-admin');
1697 }
1698 }
1699}
1700add_action( 'current_screen', 'millionairesdigest_restrict_access_to_admin_pages' );