· 8 years ago · Jun 07, 2018, 06:30 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
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/* Rename Private Message Button */
34function tweak_button_label ( $args ) {
35 $args[link_text] = 'message';
36 return $args;
37}
38add_filter( 'bp_get_send_message_button_args', 'tweak_button_label', 1, 1 );
39
40
41/* Remove Public Message Button */
42add_filter('bp_get_send_public_message_button', '__return_false');
43
44
45/* Add Support for Showing Custom Post Type "Articles" in BuddyPress Activity Streams */
46function article_activity_args() {
47 if ( ! bp_is_active( 'activity' ) ) {
48 return;
49 }
50 add_post_type_support( 'article', 'buddypress-activity' );
51 bp_activity_set_post_type_tracking_args( 'article', array(
52 'component_id' => 'activity',
53 'action_id' => 'new_article',
54 'bp_activity_admin_filter' => __( 'Wrote a new article', 'text-domain' ),
55 'bp_activity_front_filter' => __( 'Articles', 'text-domain' ),
56 'contexts' => array( 'activity', 'member' ),
57 'activity_comment' => true,
58 'bp_activity_new_post' => __( '%1$s wrote a new article, <a href="%2$s">[Article]</a>', 'text-domain' ),
59 'position' => 100,
60 ) );
61}
62add_action( 'init', 'article_activity_args' );
63function article_include_post_type_title( $action, $activity ) {
64 if ( empty( $activity->id ) ) {
65 return $action;
66 }
67 if ( 'new_article' != $activity->type ) {
68 return $action;
69 }
70 preg_match_all( '/<a.*?>([^>]*)<\/a>/', $action, $matches );
71 if ( empty( $matches[1][1] ) || '[Article]' != $matches[1][1] ) {
72 return $action;
73 }
74 $post_type_title = bp_activity_get_meta( $activity->id, 'post_title' );
75 if ( empty( $post_type_title ) ) {
76 switch_to_blog( $activity->item_id );
77 $post_type_title = get_post_field( 'post_title', $activity->secondary_item_id );
78 if ( ! empty( $post_type_title ) ) {
79 bp_activity_update_meta( $activity->id, 'post_title', $post_type_title );
80 }
81 restore_current_blog();
82 }
83 return str_replace( $matches[1][1], esc_html( $post_type_title ), $action );
84}
85add_filter( 'bp_activity_custom_post_type_post_action', 'article_include_post_type_title', 10, 2 );
86
87
88/* Add Support for Showing Custom Post Type "Videos" in BuddyPress Activity Streams */
89function video_activity_args() {
90 if ( ! bp_is_active( 'activity' ) ) {
91 return;
92 }
93 add_post_type_support( 'video', 'buddypress-activity' );
94 bp_activity_set_post_type_tracking_args( 'video', array(
95 'component_id' => 'activity',
96 'action_id' => 'new_video',
97 'bp_activity_admin_filter' => __( 'Uploaded a new video', 'text-domain' ),
98 'bp_activity_front_filter' => __( 'Videos', 'text-domain' ),
99 'contexts' => array( 'activity', 'member' ),
100 'activity_comment' => true,
101 'bp_activity_new_post' => __( '%1$s uploaded a new video, <a href="%2$s">[Video]</a>', 'text-domain' ),
102 'position' => 100,
103 ) );
104}
105add_action( 'init', 'video_activity_args' );
106function video_include_post_type_title( $action, $activity ) {
107 if ( empty( $activity->id ) ) {
108 return $action;
109 }
110 if ( 'new_video' != $activity->type ) {
111 return $action;
112 }
113 preg_match_all( '/<a.*?>([^>]*)<\/a>/', $action, $matches );
114 if ( empty( $matches[1][1] ) || '[Video]' != $matches[1][1] ) {
115 return $action;
116 }
117 $post_type_title = bp_activity_get_meta( $activity->id, 'post_title' );
118 if ( empty( $post_type_title ) ) {
119 switch_to_blog( $activity->item_id );
120 $post_type_title = get_post_field( 'post_title', $activity->secondary_item_id );
121 // We have a title save it in activity meta to avoid switching blogs too much
122 if ( ! empty( $post_type_title ) ) {
123 bp_activity_update_meta( $activity->id, 'post_title', $post_type_title );
124 }
125 restore_current_blog();
126 }
127 return str_replace( $matches[1][1], esc_html( $post_type_title ), $action );
128}
129add_filter( 'bp_activity_custom_post_type_post_action', 'video_include_post_type_title', 10, 2 );
130
131
132/* Add Support for Showing Custom Post Type "Photos" in BuddyPress Activity Streams */
133function photo_activity_args() {
134 if ( ! bp_is_active( 'activity' ) ) {
135 return;
136 }
137 add_post_type_support( 'photo', 'buddypress-activity' );
138 bp_activity_set_post_type_tracking_args( 'photo', array(
139 'component_id' => 'activity',
140 'action_id' => 'new_photo',
141 'bp_activity_admin_filter' => __( 'Uploaded a new photo', 'text-domain' ),
142 'bp_activity_front_filter' => __( 'Photos', 'text-domain' ),
143 'contexts' => array( 'activity', 'member' ),
144 'activity_comment' => true,
145 'bp_activity_new_post' => __( '%1$s uploaded a new photo, <a href="%2$s">[Photo]</a>', 'text-domain' ),
146 'position' => 100,
147 ) );
148}
149add_action( 'init', 'photo_activity_args' );
150function photo_include_post_type_title( $action, $activity ) {
151 if ( empty( $activity->id ) ) {
152 return $action;
153 }
154 if ( 'new_photo' != $activity->type ) {
155 return $action;
156 }
157 preg_match_all( '/<a.*?>([^>]*)<\/a>/', $action, $matches );
158 if ( empty( $matches[1][1] ) || '[Photo]' != $matches[1][1] ) {
159 return $action;
160 }
161 $post_type_title = bp_activity_get_meta( $activity->id, 'post_title' );
162 if ( empty( $post_type_title ) ) {
163 switch_to_blog( $activity->item_id );
164 $post_type_title = get_post_field( 'post_title', $activity->secondary_item_id );
165 // We have a title save it in activity meta to avoid switching blogs too much
166 if ( ! empty( $post_type_title ) ) {
167 bp_activity_update_meta( $activity->id, 'post_title', $post_type_title );
168 }
169 restore_current_blog();
170 }
171 return str_replace( $matches[1][1], esc_html( $post_type_title ), $action );
172}
173add_filter( 'bp_activity_custom_post_type_post_action', 'photo_include_post_type_title', 10, 2 );
174
175
176/* Add Support for Showing Custom Post Type "Music" in BuddyPress Activity Streams */
177function audio_activity_args() {
178 if ( ! bp_is_active( 'activity' ) ) {
179 return;
180 }
181 add_post_type_support( 'audio', 'buddypress-activity' );
182 bp_activity_set_post_type_tracking_args( 'audio', array(
183 'component_id' => 'activity',
184 'action_id' => 'new_audio',
185 'bp_activity_admin_filter' => __( 'Uploaded a new song', 'text-domain' ),
186 'bp_activity_front_filter' => __( 'Music', 'text-domain' ),
187 'contexts' => array( 'activity', 'member' ),
188 'activity_comment' => true,
189 'bp_activity_new_post' => __( '%1$s uploaded a new song, <a href="%2$s">[Song]</a>', 'text-domain' ),
190 'position' => 100,
191 ) );
192}
193add_action( 'init', 'audio_activity_args' );
194function audio_include_post_type_title( $action, $activity ) {
195 if ( empty( $activity->id ) ) {
196 return $action;
197 }
198 if ( 'new_audio' != $activity->type ) {
199 return $action;
200 }
201 preg_match_all( '/<a.*?>([^>]*)<\/a>/', $action, $matches );
202 if ( empty( $matches[1][1] ) || '[Song]' != $matches[1][1] ) {
203 return $action;
204 }
205 $post_type_title = bp_activity_get_meta( $activity->id, 'post_title' );
206 if ( empty( $post_type_title ) ) {
207 switch_to_blog( $activity->item_id );
208 $post_type_title = get_post_field( 'post_title', $activity->secondary_item_id );
209 // We have a title save it in activity meta to avoid switching blogs too much
210 if ( ! empty( $post_type_title ) ) {
211 bp_activity_update_meta( $activity->id, 'post_title', $post_type_title );
212 }
213 restore_current_blog();
214 }
215 return str_replace( $matches[1][1], esc_html( $post_type_title ), $action );
216}
217add_filter( 'bp_activity_custom_post_type_post_action', 'audio_include_post_type_title', 10, 2 );
218
219
220/* Add Support for Allowing Featued Images for Custom Post Type "Articles" to Be Displayed in BuddyPress Activity Streams */
221function article_bp_activity_entry_meta() {
222 if ( bp_get_activity_type() == 'new_article' ) {?>
223 <?php
224 global $wpdb, $post, $bp;
225 $theimg = wp_get_attachment_image_src( get_post_thumbnail_id( bp_get_activity_secondary_item_id() ), 'large' );
226 ?>
227 <img src="<?php echo $theimg[0]; ?>" >
228 <?php }
229}
230add_action('bp_activity_excerpt_append_text', 'article_bp_activity_entry_meta');
231
232
233/* Add Support for Allowing Featued Images for Custom Post Type "Photos" to Be Displayed in BuddyPress Activity Streams */
234function photo_bp_activity_entry_meta() {
235 if ( bp_get_activity_type() == 'new_photo' ) {?>
236 <?php
237 global $wpdb, $post, $bp;
238 $theimg = wp_get_attachment_image_src( get_post_thumbnail_id( bp_get_activity_secondary_item_id() ), 'large' );
239 ?>
240 <img src="<?php echo $theimg[0]; ?>" >
241 <?php }
242}
243add_action('bp_activity_excerpt_append_text', 'photo_bp_activity_entry_meta');
244
245
246/* Remove Categories & Tag Labels from Author's Statistics Widget */
247add_filter('apsw_taxonomy_category', 'apsw_taxonomy_category');
248 if (!function_exists('apsw_taxonomy_category')) {
249 function apsw_taxonomy_category($categoryList) {
250 return null;
251 }
252 }
253add_filter('apsw_taxonomy_post_tag', 'apsw_taxonomy_post_tag');
254 if (!function_exists('apsw_taxonomy_post_tag')) {
255 function apsw_taxonomy_post_tag($tagList) {
256 return null;
257 }
258 }
259add_filter('apsw_taxonomy_custom', 'apsw_taxonomy_custom');
260 if (!function_exists('apsw_taxonomy_custom')) {
261 function apsw_taxonomy_custom($taxonomyList) {
262 return null;
263 }
264 }
265
266
267/* Add Support for Allowing Custom Post Type "Articles" to be Submitted & Published in BuddyPress Activity Streams and Frontend */
268function generate_article_from_form_submission() {
269 // Get the submitted field values
270 $post_title = af_get_field( 'article_title' );
271 $post_content = af_get_field( 'article_content' );
272 // Set up a form using the values for post title and content
273 // Replace post_type with whatever type of post you want to generate
274 $post_data = array(
275 'post_type' => 'article',
276 'post_status' => 'publish',
277 'post_title' => $post_title,
278 'post_content' => $post_content,
279 );
280 // Create post with the previously retrieved values
281 $post_id = wp_insert_post( $post_data );
282 // Save extra_information field directly to custom field on post
283 af_save_field( '_thumbnail_id', $post_id );
284}
285add_action( 'af/form/submission/key=form_5a6d550fa348b', 'generate_article_from_form_submission', 10 );
286
287
288/* Add Support for Allowing Custom Post Type "Videos" to be Submitted & Published in BuddyPress Activity Streams and Frontend */
289function generate_video_from_form_submission() {
290 // Get the submitted field values
291 $post_title = af_get_field( 'video_title' );
292 $post_content = af_get_field( 'video_link' );
293 // Set up a form using the values for post title and content
294 // Replace post_type with whatever type of post you want to generate
295 $post_data = array(
296 'post_type' => 'video',
297 'post_status' => 'publish',
298 'post_title' => $post_title,
299 'post_content' => $post_content,
300 );
301 // Create post with the previously retrieved values
302 $post_id = wp_insert_post( $post_data );
303 // Save extra_information field directly to custom field on post
304 af_save_field( 'video_content', $post_id );
305}
306add_action( 'af/form/submission/key=form_5a7606d26943d', 'generate_video_from_form_submission', 10 );
307
308
309/* Add Support for Allowing Custom Post Type "Photos" to be Submitted & Published in BuddyPress Activity Streams and Frontend */
310function generate_photo_from_form_submission() {
311 // Get the submitted field values
312 $post_title = af_get_field( 'photo_title' );
313 $post_content = af_get_field( 'photo_content' );
314 // Set up a form using the values for post title and content
315 // Replace post_type with whatever type of post you want to generate
316 $post_data = array(
317 'post_type' => 'photo',
318 'post_status' => 'publish',
319 'post_title' => $post_title,
320 'post_content' => $post_content,
321 );
322 // Create post with the previously retrieved values
323 $post_id = wp_insert_post( $post_data );
324 // Save extra_information field directly to custom field on post
325 af_save_field( '_thumbnail_id', $post_id );
326}
327add_action( 'af/form/submission/key=form_5a76139d04770', 'generate_photo_from_form_submission', 10 );
328
329
330/* Add Support for Allowing Custom Post Type "Music" to be Submitted & Published in BuddyPress Activity Streams and Frontend */
331function generate_audio_from_form_submission() {
332 // Get the submitted field values
333 $post_title = af_get_field( 'audio_title' );
334 $post_content = af_get_field( 'audio_link' );
335 // Set up a form using the values for post title and content
336 // Replace post_type with whatever type of post you want to generate
337 $post_data = array(
338 'post_type' => 'audio',
339 'post_status' => 'publish',
340 'post_title' => $post_title,
341 'post_content' => $post_content,
342 );
343 // Create post with the previously retrieved values
344 $post_id = wp_insert_post( $post_data );
345 // Save extra_information field directly to custom field on post
346 af_save_field( 'audio_artist', $post_id );
347 af_save_field( 'audio_genre', $post_id );
348 af_save_field( 'audio_content', $post_id );
349}
350add_action( 'af/form/submission/key=form_5a7613a051921', 'generate_audio_from_form_submission', 10 );
351
352
353/* Add Support for Single Line WYSIWYG to Advanced Custom Fields Pro */
354define('MEDIUM_EDITOR_THEME', 'kleo');
355add_filter('medium-editor-theme', 'my_medium_editor_theme_function');
356function my_medium_editor_theme_function($theme) {
357 $theme = 'kleo';
358 return $theme;
359}
360
361
362/* Change Admin Display Name to Founder */
363function change_role_name() {
364 global $wp_roles;
365 if ( ! isset( $wp_roles ) )
366 $wp_roles = new WP_Roles();
367 $wp_roles->roles['administrator']['name'] = 'Founder';
368 $wp_roles->role_names['administrator'] = 'Founder';
369}
370add_action('init', 'change_role_name');
371
372
373/* 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. */
374add_action('bp_init', 'md_bpxps_init');
375function md_bpxps_init() {
376 add_shortcode('xprofile', 'md_bpxps_xprofile_shortcode');
377}
378function md_bpxps_xprofile_shortcode($attributes) {
379 if(empty($attributes['field'])) return false;
380 extract($attributes);
381 $user_id = (isset($user)) ? $user : false;
382 global $bp;
383 if (!empty($user_id) && intval($user_id)===0) {
384 // shortcode-defined username
385 $user_id = get_user_by( 'slug', $user_id);
386 }
387 if ((isset($user) && $user=='displayed') ||
388 (empty($user_id) && isset($bp->displayed_user->id))) {
389 // On profile page, show the displayed user's information
390 $user_id = $bp->displayed_user->id;
391 }
392 global $post;
393 if ((isset($user) && $user=='author') ||
394 (empty($user_id) && !empty($post->post_author))) {
395 // On author or single post page, show the author's information
396 $user_id = $post->post_author;
397 }
398 if ((isset($user) && $user=='current') ||
399 (empty($user_id) && is_user_logged_in())) {
400 // Show the currently logged in user's information
401 $user_id = get_current_user_id();
402 }
403 if (empty($user_id)) return false;
404 return xprofile_get_field_data($field, $user_id);
405}
406
407
408/* 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. */
409/* If a YouTube or Vimeo video is added in the post content, grab its thumbnail and set it as the featured image. */
410function millionairesdigest_set_media_as_featured_image( $post_id, $post ) {
411
412 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
413 return;
414 }
415 if ( wp_is_post_revision( $post_id ) ) {
416 return;
417 }
418 $content = isset( $post->post_content ) ? $post->post_content : '';
419 // Only check the first 800 characters of our post.
420 $content = substr( $content, 0, 800 );
421 // Allow developers to filter the content to allow for searching in postmeta or other places.
422 $content = apply_filters( 'millionairesdigest_featured_images_from_video_filter_content', $content );
423 // Props to @rzen for lending his massive brain smarts to help with the regex.
424 $do_video_thumbnail = (
425 $post_id
426 && ! has_post_thumbnail( $post_id )
427 && $content
428 // Get the video and thumb URLs if they exist.
429 && ( preg_match( '/\/\/(www\.)?(youtu|youtube)\.(com|be)\/(watch|embed)?\/?(\?v=)?([a-zA-Z0-9\-\_]+)/', $content, $youtube_matches )
430 || preg_match( '#https?://(.+\.)?vimeo\.com/.*#i', $content, $vimeo_matches ) )
431 );
432 if ( ! $do_video_thumbnail ) {
433 return update_post_meta( $post_id, '_is_video', false );
434 }
435 $video_thumbnail_url = false;
436 $youtube_id = ! empty( $youtube_matches ) ? $youtube_matches[6] : '';
437 $vimeo_id = ! empty( $vimeo_matches ) ? preg_replace( "/[^0-9]/", "", $vimeo_matches[0] ) : '';
438 if ( $youtube_id ) {
439 // Check to see if our max-res image exists.
440 $remote_headers = wp_remote_head( 'http://img.youtube.com/vi/' . $youtube_id . '/maxresdefault.jpg' );
441 $is_404 = ( 404 === wp_remote_retrieve_response_code( $remote_headers ) );
442 $video_thumbnail_url = ( ! $is_404 ) ? 'http://img.youtube.com/vi/' . $youtube_id . '/maxresdefault.jpg' : 'http://img.youtube.com/vi/' . $youtube_id . '/hqdefault.jpg';
443 } elseif ( $vimeo_id ) {
444 $vimeo_data = wp_remote_get( 'http://www.vimeo.com/api/v2/video/' . intval( $vimeo_id ) . '.php' );
445 if ( isset( $vimeo_data['response']['code'] ) && '200' == $vimeo_data['response']['code'] ){
446 $response = unserialize( $vimeo_data['body'] );
447 $video_thumbnail_url = isset( $response[0]['thumbnail_large'] ) ? $response[0]['thumbnail_large'] : false;
448 }
449 }
450 // If we found an image...
451 $attachment_id = $video_thumbnail_url && ! is_wp_error( $video_thumbnail_url )
452 // Then sideload it.
453 ? 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() ) ) )
454 // No thumbnail url found.
455 : 0;
456 // If attachment wasn't created, bail.
457 if ( ! $attachment_id ) {
458 return;
459 }
460 // Woot! we got an image, so set it as the post thumbnail.
461 set_post_thumbnail( $post_id, $attachment_id );
462 update_post_meta( $post_id, '_is_video', true );
463}
464add_action( 'save_post', 'millionairesdigest_set_media_as_featured_image', 10, 2 );
465/**
466 * Handle the upload of a new image.
467 *
468 * @since 1.0.0
469 *
470 * @param string $url URL to sideload.
471 * @param int $post_id Post ID to attach to.
472 * @param string|null $filename Filename to use.
473 * @return mixed
474 */
475function millionairesdigest_ms_media_sideload_image_with_new_filename( $url, $post_id, $filename = null ) {
476 if ( ! $url || ! $post_id ) {
477 return new WP_Error( 'missing', __( 'Need a valid URL and post ID...', 'automatic-featured-images-from-videos' ) );
478 }
479 require_once( ABSPATH . 'wp-admin/includes/file.php' );
480 // Download file to temp location, returns full server path to temp file, ex; /home/user/public_html/mysite/wp-content/26192277_640.tmp.
481 $tmp = download_url( $url );
482 // If error storing temporarily, unlink.
483 if ( is_wp_error( $tmp ) ) {
484 // Clean up.
485 @unlink( $file_array['tmp_name'] );
486 $file_array['tmp_name'] = '';
487 // And output wp_error.
488 return $tmp;
489 }
490 // Fix file filename for query strings.
491 preg_match( '/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $url, $matches );
492 // Extract filename from url for title.
493 $url_filename = basename($matches[0]);
494 // Determine file type (ext and mime/type).
495 $url_type = wp_check_filetype($url_filename);
496 // Override filename if given, reconstruct server path.
497 if ( !empty( $filename ) ) {
498 $filename = sanitize_file_name( $filename );
499 // Extract path parts.
500 $tmppath = pathinfo( $tmp );
501 // Build new path.
502 $new = $tmppath['dirname'] . '/'. $filename . '.' . $tmppath['extension'];
503 // Renames temp file on server.
504 rename($tmp, $new);
505 // Push new filename (in path) to be used in file array later.
506 $tmp = $new;
507 }
508 /* Assemble file data (should be built like $_FILES since wp_handle_sideload() will be using). */
509 // Full server path to temp file.
510 $file_array['tmp_name'] = $tmp;
511 if ( !empty( $filename ) ) {
512 // User given filename for title, add original URL extension.
513 $file_array['name'] = $filename . '.' . $url_type['ext'];
514 } else {
515 // Just use original URL filename.
516 $file_array['name'] = $url_filename;
517 }
518 $post_data = array(
519 // Just use the original filename (no extension).
520 'post_title' => get_the_title( $post_id ),
521 // Make sure gets tied to parent.
522 'post_parent' => $post_id,
523 );
524 // Required libraries for media_handle_sideload.
525 require_once( ABSPATH . 'wp-admin/includes/file.php' );
526 require_once( ABSPATH . 'wp-admin/includes/media.php' );
527 require_once( ABSPATH . 'wp-admin/includes/image.php' );
528 // Do the validation and storage stuff.
529 // $post_data can override the items saved to wp_posts table, like post_mime_type, guid, post_parent, post_title, post_content, post_status.
530 $att_id = media_handle_sideload( $file_array, $post_id, null, $post_data );
531 // If error storing permanently, unlink.
532 if ( is_wp_error( $att_id ) ) {
533 // Clean up.
534 @unlink( $file_array['tmp_name'] );
535 // And output wp_error.
536 return $att_id;
537 }
538 return $att_id;
539}
540
541
542/* Add Support for Allowing Users to Receive Comment Notifications Left on Their Posts. Note: This includes all post types. */
543class BDBP_Blog_Comment_Notifier {
544 private static $instance;
545 private $id = 'blog_comment_notifier';
546 private function __construct() {
547 $this->setup();
548 }
549 public static function get_instance() {
550 if ( ! isset( self::$instance ) ) {
551 self::$instance = new self();
552 }
553 return self::$instance;
554 }
555 public function setup() {
556 add_action( 'bp_setup_globals', array( $this, 'setup_globals' ) );
557 //On New comment
558 add_action( 'comment_post', array( $this, 'comment_posted' ), 15, 2 );
559 //on delete post, we should delete all notifications for the comment on that post
560 //add_action( 'delete_post', array( $this, 'post_deleted' ), 10, 2 );
561 // Monitor actions on existing comments
562 add_action( 'deleted_comment', array( $this, 'comment_deleted' ) );
563 //add_action( 'trashed_comment', array( $this, 'comment_deleted' ) );
564 //add_action( 'spam_comment', array( $this, 'comment_deleted' ) );
565 //should we do something on the action untrash_comment & unspam_comment
566 add_action( 'wp_set_comment_status', array( $this, 'comment_status_changed' ) );
567 // Load plugin text domain
568 add_action( 'bp_init', array( $this, 'load_textdomain' ) );
569 add_action( 'template_redirect', array( $this, 'mark_read' ) );
570 }
571 public function load_textdomain() {
572 load_plugin_textdomain( 'bp-notify-post-author-on-blog-comment', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
573 }
574 public function setup_globals() {
575 if ( ! defined( 'BD_BLOG_NOTIFIER_SLUG' ) ) {
576 define( 'BD_BLOG_NOTIFIER_SLUG', 'bd-blog-notifier' );
577 }
578 $bp = buddypress();
579 $bp->blog_comment_notifier = new stdClass();
580 $bp->blog_comment_notifier->id = $this->id;//I asume others are not going to use this is
581 $bp->blog_comment_notifier->slug = BD_BLOG_NOTIFIER_SLUG;
582 $bp->blog_comment_notifier->notification_callback = array( $this, 'format_notifications' );//show the notification
583 $bp->active_components[ $bp->blog_comment_notifier->id ] = $bp->blog_comment_notifier->id;
584 do_action( 'blog_comment_notifier_setup_globals' );
585 }
586 public function comment_posted( $comment_id = 0, $comment_status = 0 ) {
587 if ( ! $this->is_bp_active() ) {
588 return ;
589 }
590 $comment = get_comment( $comment_id );
591 if ( empty( $comment ) || $comment->comment_approved == 'spam' ) {
592 return ;
593 }
594 if ( $comment->comment_type == 'trackback' || $comment->comment_type == 'pingback' ) {
595 return ;
596 }
597 $post_id = $comment->comment_post_ID;
598 $post = get_post( $post_id );
599 if ( $post->post_author == $comment->user_id ) {
600 return ;
601 }
602 if ( ! user_can( $post->post_author, 'moderate_comments' ) && $comment->comment_approved == 0 ) {
603 return;
604 }
605 $this->notify( $post->post_author, $comment );
606 }
607 public function comment_status_changed( $comment_id = 0, $comment_status = 0 ) {
608 if ( ! $this->is_bp_active() ) {
609 return ;
610 }
611 $comment = get_comment( $comment_id );
612 if ( empty( $comment ) ) {
613 return ;
614 }
615 if ( $comment->comment_approved == 'spam' || $comment->comment_approve == 'trash' ) {
616 if ( $this->is_notified( $comment_id ) ) {
617 $this->comment_deleted( $comment_id );
618 }
619 return;
620 }
621 if ( $comment->comment_approve == 0 && $this->is_notified( $comment_id ) ) {
622 $this->comment_deleted( $comment_id );
623 return ;
624 }
625 if ( $comment->comment_approve == 1 ) {
626 $post = get_post( $comment->comment_post_ID );
627 if ( get_current_user_id() == $post->post_author ) {
628 if ( $this->is_notified( $comment_id ) ) {
629 $this->comment_deleted ( $comment_id );
630 }
631 return ;
632 } else {
633 $this->notify( $post->post_author, $comment );
634 }
635 }
636 }
637 public function comment_deleted( $comment_id ) {
638 if ( ! $this->is_bp_active() ) {
639 return;
640 }
641 bp_notifications_delete_all_notifications_by_type( $comment_id, $this->id );
642 $this->unmark_notified( $comment_id );
643 }
644 public function format_notifications( $action, $comment_id, $secondary_item_id, $total_items, $format = 'string', $notification_id = 0 ) {
645 $bp = buddypress();
646 $switched = false;
647 $blog_id = bp_notifications_get_meta( $notification_id, '_blog_id' );
648 if ( $blog_id && get_current_blog_id() != $blog_id ) {
649 switch_to_blog( $blog_id );
650 $switched = true;
651 }
652 $comment = get_comment( $comment_id );
653 $post = get_post( $comment->comment_post_ID);
654 $link = $text = $name = $post_title = $comment_content ='';
655 if ( $comment->user_id ) {
656 $name = bp_core_get_user_displayname ( $comment->user_id );
657 } else {
658 $name = $comment->comment_author;
659 }
660 $post_title = $post->post_title;
661 $comment_content = wp_trim_words( $comment->comment_content, 12, ' ...' );
662 $text = sprintf(
663 __( '%s commented on <strong>%s</strong>: <em>%s</em>', 'bp-notify-post-author-on-blog-comment' ),
664 $name,
665 $post_title,
666 $comment_content
667 );
668 if ( $comment->comment_approved == 1 ) {
669 $link = get_comment_link ( $comment );
670 } else {
671 $link =admin_url( 'comment.php?action=approve&c=' . $comment_id );
672 }
673 if( $switched ) {
674 restore_current_blog();
675 }
676 if ( $format == 'string' ) {
677 return apply_filters( 'bp_blog_notieifier_new_comment_notification_string', '<a href="' . $link . '">' . $text . '</a>' );
678 }else{
679 return array(
680 'link' => $link,
681 'text' => $text);
682 }
683 return false;
684 }
685 public function is_bp_active() {
686 if ( function_exists( 'buddypress' ) ) {
687 return true;
688 }
689 return false;
690 }
691 public function is_notified( $comment_id ) {
692 return get_comment_meta( $comment_id, 'bd_post_author_notified', true );
693 }
694 public function mark_notified( $comment_id ) {
695 update_comment_meta( $comment_id, 'bd_post_author_notified', 1 );
696 }
697 public function unmark_notified( $comment_id ) {
698 delete_comment_meta( $comment_id, 'bd_post_author_notified' );
699 }
700 public function notify( $user_id, $comment ) {
701 $comment_id = $comment->comment_ID;
702 $notificatin_id = bp_notifications_add_notification( array(
703 'item_id' => $comment_id,
704 'user_id' => $user_id,
705 'component_name' => $this->id,
706 'component_action' => 'new_blog_comment_'. $comment_id,
707 'secondary_item_id' => $comment->comment_post_ID,
708 ));
709 if ( $notificatin_id && is_multisite() ) {
710 bp_notifications_add_meta( $notificatin_id, '_blog_id', get_current_blog_id() );
711 }
712 $this->mark_notified( $comment_id );
713 }
714 public function mark_read() {
715 if ( ! $this->is_bp_active() || ! is_singular() ) {
716 return ;
717 }
718 $post_id = get_queried_object_id();
719 if ( ! $post_id ) {
720 return ;
721 }
722 return BP_Notifications_Notification::update(
723 array( 'is_new' => 0 ),
724 array( 'secondary_item_id' => $post_id,
725 'component_name' => $this->id,
726 'user_id' => get_current_user_id(),
727 )
728 );
729 }
730}
731BDBP_Blog_Comment_Notifier::get_instance();
732
733
734/* 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 */
735function millionairesdigest_hide_add_friend_button( $button ) {
736 $displayed_user_id = bp_displayed_user_id();
737 $user_id = ( $displayed_user_id ) ? $displayed_user_id : bp_get_member_user_id();
738 $member_type = bp_get_member_type( $user_id );
739 // Do Not Display the "Add Friend" Button for the Following Member Types
740 $not_in = array( 'brand', 'famous-people', 'organization' );
741 if ( ! in_array( $member_type, $not_in, true ) ) {
742 return $button;
743 }
744 return '';
745}
746add_filter('bp_get_add_friend_button', 'millionairesdigest_hide_add_friend_button');
747
748
749/* 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 */
750function md_hide_add_friend_button( $button ) {
751 if ( is_super_admin() ) {
752 return $button;
753 }
754 $displayed_user_id = bp_loggedin_user_id();
755 $user_id = ( $displayed_user_id ) ? $displayed_user_id : bp_get_member_user_id();
756 $member_type = bp_get_member_type( $user_id );
757 // Do Not Display the "Add Friend" Button for the Following Member Types
758 $not_in = array( 'brand', 'famous-person', 'organization' );
759 if ( ! in_array( $member_type, $not_in, true ) ) {
760 return $button;
761 }
762 return '';
763}
764add_filter('bp_get_add_friend_button', 'md_hide_add_friend_button');
765
766
767/* 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 */
768function millionairesdigest_hide_add_follow_button( $button ) {
769 $displayed_user_id = bp_displayed_user_id();
770 $user_id = ( $displayed_user_id ) ? $displayed_user_id : bp_get_member_user_id();
771 $member_type = bp_get_member_type( $user_id );
772 // Do Not Display the "Follow" Button for the Following Member Types
773 $not_in = array( 'user' );
774 if ( ! in_array( $member_type, $not_in, true ) ) {
775 return $button;
776 }
777 return '';
778}
779add_filter('bp_follow_get_add_follow_button', 'millionairesdigest_hide_add_follow_button');
780
781
782/* 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 */
783function millionairesdigest_remove_mutual_friends() {
784 if ( is_super_admin() ) {
785 return;
786 }
787 if ( ! bp_is_user() ) {
788 return;
789 }
790 $user_id = bp_loggedin_user_id();
791 if ( ! bp_has_member_type( $user_id, 'user' ) && ( ! bp_has_member_type( $user_id, 'famous-person' ) && ( ! bp_has_member_type( $user_id, 'millionaires-digest' ) ) ) ) {
792 bp_core_remove_nav_item( 'mutual-friends' );
793 }
794}
795add_action( 'bp_setup_nav', 'millionairesdigest_remove_mutual_friends', 1001 );
796
797
798/* 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 */
799function millionairedigest_remove_mutual_friends() {
800 if ( is_super_admin() ) {
801 return;
802 }
803 if ( ! bp_is_user() ) {
804 return;
805 }
806 $user_id = bp_displayed_user_id();
807 if ( ! bp_has_member_type( $user_id, 'user' ) && ( ! bp_has_member_type( $user_id, 'famous-person' ) && ( ! bp_has_member_type( $user_id, 'millionaires-digest' ) ) ) ) {
808 bp_core_remove_nav_item( 'mutual-friends' );
809 }
810}
811add_action( 'bp_setup_nav', 'millionairedigest_remove_mutual_friends', 1001 );
812
813
814/* 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 */
815function millionairesdigest_remove_followers() {
816 if ( ! bp_is_user() ) {
817 return;
818 }
819 $user_id = bp_displayed_user_id();
820 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' ) ) ) ) ) {
821 bp_core_remove_nav_item( 'followers' );
822 }
823}
824add_action( 'bp_setup_nav', 'millionairesdigest_remove_followers', 1001 );
825
826
827/* 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 */
828function millionairedigest_remove_friends() {
829 if ( is_super_admin() ) {
830 return;
831 }
832 if ( ! bp_is_user() ) {
833 return;
834 }
835 $user_id = bp_displayed_user_id();
836 if ( ! bp_has_member_type( $user_id, 'user' ) && ( ! bp_has_member_type( $user_id, 'millionaires-digest' ) ) ) {
837 bp_core_remove_nav_item( 'friends' );
838 }
839}
840add_action( 'bp_setup_nav', 'millionairedigest_remove_friends', 1001 );
841
842
843/* Add a "Brands I've Added to My Feed" Widget to All User's Profiles */
844class BP_Brands_Following_Widget extends WP_Widget {
845 function __construct() {
846 // Set up optional widget args.
847 $widget_ops = array(
848 'classname' => 'widget_bp_brands_following_widget widget buddypress',
849 'description' => __( "Show a list of brand accounts that the displayed user has added to their feed.", 'buddypress-followers' )
850 );
851 // Set up the widget.
852 parent::__construct(
853 false,
854 __( "(BP Follow) Brands I've Added to My Feeds", 'buddypress-followers' ),
855 $widget_ops
856 );
857 }
858 //Displays the widget.
859 function widget( $args, $instance, $member_args ) {
860 if ( empty( $instance['max_users'] ) ) {
861 $instance['max_users'] = 16;
862 }
863 // If the displayed user hasn't added any brand accounts, then hide the widget.
864 if ( ! $following = bp_get_following_ids( array( 'user_id' => bp_displayed_user_id() ) ) ) {
865 return false;
866 }
867 // If the displayed user has added brand accounts to their feed, then show the profile photos of the brand accounts.
868 if ( bp_has_members( array(
869 'include' => $following,
870 'max' => $instance['max_users'],
871 'populate_extras' => false,
872 'type' => 'active',
873 'member_type' => 'brand'
874 ) ) ) {
875 do_action( 'bp_before_following_widget' );
876 echo $args['before_widget'];
877 echo $args['before_title']
878 . $instance['title']
879 . $args['after_title'];
880 ?>
881 <div class="avatar-block">
882 <?php while ( bp_members() ) : bp_the_member(); ?>
883 <div class="item-avatar">
884 <a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_avatar() ?></a>
885 </div>
886 <?php endwhile; ?>
887 </div>
888 <?php echo $args['after_widget']; ?>
889 <?php do_action( 'bp_after_following_widget' ); ?>
890 <?php
891 }
892 }
893 //Callback to save widget settings.
894 function update( $new_instance, $old_instance ) {
895 $instance = $old_instance;
896 $instance['title'] = strip_tags( $new_instance['title'] );
897 $instance['max_users'] = (int) $new_instance['max_users'];
898 return $instance;
899 }
900 //Widget settings form.
901 function form( $instance ) {
902 $instance = wp_parse_args( (array) $instance, array(
903 'title' => __( "Brand Accounts I've Added to My Feeds", 'buddypress-followers' ),
904 'max_users' => 16
905 ) );
906 ?>
907 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
908 <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>
909 <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>
910 <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>
911 <?php
912 }
913}
914add_action( 'widgets_init', create_function( '', 'return register_widget("BP_Brands_Following_Widget");' ) );
915
916
917/* Add a "Famous People I've Added to My Feed" Widget to All User's Profiles */
918class BP_Famous_People_Following_Widget extends WP_Widget {
919 function __construct() {
920 // Set up optional widget args.
921 $widget_ops = array(
922 'classname' => 'widget_bp_famous_people_following_widget widget buddypress',
923 'description' => __( "Show a list of famous people accounts that the displayed user has added to their feed.", 'buddypress-followers' )
924 );
925 // Set up the widget.
926 parent::__construct(
927 false,
928 __( "(BP Follow) Famous People I've Added to My Feeds", 'buddypress-followers' ),
929 $widget_ops
930 );
931 }
932 //Displays the widget.
933 function widget( $args, $instance, $member_args ) {
934 if ( empty( $instance['max_users'] ) ) {
935 $instance['max_users'] = 16;
936 }
937 // If the displayed user hasn't added any famous people accounts, then hide the widget.
938 if ( ! $following = bp_get_following_ids( array( 'user_id' => bp_displayed_user_id() ) ) ) {
939 return false;
940 }
941 // If the displayed user has added famous people accounts to their feed, then show the profile photos of the famous people accounts.
942 if ( bp_has_members( array(
943 'include' => $following,
944 'max' => $instance['max_users'],
945 'populate_extras' => false,
946 'type' => 'active',
947 'member_type' => 'famous-person'
948 ) ) ) {
949 do_action( 'bp_before_following_widget' );
950 echo $args['before_widget'];
951 echo $args['before_title']
952 . $instance['title']
953 . $args['after_title'];
954 ?>
955 <div class="avatar-block">
956 <?php while ( bp_members() ) : bp_the_member(); ?>
957 <div class="item-avatar">
958 <a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_avatar() ?></a>
959 </div>
960 <?php endwhile; ?>
961 </div>
962 <?php echo $args['after_widget']; ?>
963 <?php do_action( 'bp_after_following_widget' ); ?>
964 <?php
965 }
966 }
967 //Callback to save widget settings.
968 function update( $new_instance, $old_instance ) {
969 $instance = $old_instance;
970 $instance['title'] = strip_tags( $new_instance['title'] );
971 $instance['max_users'] = (int) $new_instance['max_users'];
972 return $instance;
973 }
974 //Widget settings form.
975 function form( $instance ) {
976 $instance = wp_parse_args( (array) $instance, array(
977 'title' => __( "Famous People Accounts I've Added to My Feeds", 'buddypress-followers' ),
978 'max_users' => 16
979 ) );
980 ?>
981 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
982 <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>
983 <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>
984 <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>
985 <?php
986 }
987}
988add_action( 'widgets_init', create_function( '', 'return register_widget("BP_Famous_People_Following_Widget");' ) );
989
990
991/* Add an "Organizations I've Added to My Feed" Widget to All User's Profiles */
992class BP_Organizations_Following_Widget extends WP_Widget {
993 function __construct() {
994 // Set up optional widget args.
995 $widget_ops = array(
996 'classname' => 'widget_bp_organizations_following_widget widget buddypress',
997 'description' => __( "Show a list of organization accounts that the displayed user has added to their feed.", 'buddypress-followers' )
998 );
999 // Set up the widget.
1000 parent::__construct(
1001 false,
1002 __( "(BP Follow) Organizations I've Added to My Feeds", 'buddypress-followers' ),
1003 $widget_ops
1004 );
1005 }
1006 //Displays the widget.
1007 function widget( $args, $instance, $member_args ) {
1008 if ( empty( $instance['max_users'] ) ) {
1009 $instance['max_users'] = 16;
1010 }
1011 // If the displayed user hasn't added any organization accounts, then hide the widget.
1012 if ( ! $following = bp_get_following_ids( array( 'user_id' => bp_displayed_user_id() ) ) ) {
1013 return false;
1014 }
1015 // If the displayed user has added organization accounts to their feed, then show the profile photos of the organization accounts.
1016 if ( bp_has_members( array(
1017 'include' => $following,
1018 'max' => $instance['max_users'],
1019 'populate_extras' => false,
1020 'type' => 'active',
1021 'member_type' => 'organization'
1022 ) ) ) {
1023 do_action( 'bp_before_following_widget' );
1024 echo $args['before_widget'];
1025 echo $args['before_title']
1026 . $instance['title']
1027 . $args['after_title'];
1028 ?>
1029 <div class="avatar-block">
1030 <?php while ( bp_members() ) : bp_the_member(); ?>
1031 <div class="item-avatar">
1032 <a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_avatar() ?></a>
1033 </div>
1034 <?php endwhile; ?>
1035 </div>
1036 <?php echo $args['after_widget']; ?>
1037 <?php do_action( 'bp_after_following_widget' ); ?>
1038 <?php
1039 }
1040 }
1041 //Callback to save widget settings.
1042 function update( $new_instance, $old_instance ) {
1043 $instance = $old_instance;
1044 $instance['title'] = strip_tags( $new_instance['title'] );
1045 $instance['max_users'] = (int) $new_instance['max_users'];
1046 return $instance;
1047 }
1048 //Widget settings form.
1049 function form( $instance ) {
1050 $instance = wp_parse_args( (array) $instance, array(
1051 'title' => __( "Organization Accounts I've Added to My Feeds", 'buddypress-followers' ),
1052 'max_users' => 16
1053 ) );
1054 ?>
1055 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
1056 <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>
1057 <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>
1058 <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>
1059 <?php
1060 }
1061}
1062add_action( 'widgets_init', create_function( '', 'return register_widget("BP_Organizations_Following_Widget");' ) );
1063
1064
1065/* Add a "Millionaire's Digest Accounts I've Added to My Feed" Widget to All User's Profiles */
1066class BP_Millionaires_Digest_Following_Widget extends WP_Widget {
1067 function __construct() {
1068 // Set up optional widget args.
1069 $widget_ops = array(
1070 'classname' => 'widget_bp_millionaires_digest_following_widget widget buddypress',
1071 'description' => __( "Show a list of Millionaire's Digest accounts that the displayed user has added to their feed.", 'buddypress-followers' )
1072 );
1073 // Set up the widget.
1074 parent::__construct(
1075 false,
1076 __( "(BP Follow) Millionaire's Digest Accounts I've Added to My Feeds", 'buddypress-followers' ),
1077 $widget_ops
1078 );
1079 }
1080 //Displays the widget.
1081 function widget( $args, $instance, $member_args ) {
1082 if ( empty( $instance['max_users'] ) ) {
1083 $instance['max_users'] = 16;
1084 }
1085 // If the displayed user hasn't added any brand accounts, then hide the widget.
1086 if ( ! $following = bp_get_following_ids( array( 'user_id' => bp_displayed_user_id() ) ) ) {
1087 return false;
1088 }
1089 // If the displayed user has added Millionaire's Digest accounts to their feed, then show the profile photos of the Millionaire's Digest accounts.
1090 if ( bp_has_members( array(
1091 'include' => $following,
1092 'max' => $instance['max_users'],
1093 'populate_extras' => false,
1094 'type' => 'active',
1095 'member_type' => 'millionaires-digest'
1096 ) ) ) {
1097 do_action( 'bp_before_following_widget' );
1098 echo $args['before_widget'];
1099 echo $args['before_title']
1100 . $instance['title']
1101 . $args['after_title'];
1102 ?>
1103 <div class="avatar-block">
1104 <?php while ( bp_members() ) : bp_the_member(); ?>
1105 <div class="item-avatar">
1106 <a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_avatar() ?></a>
1107 </div>
1108 <?php endwhile; ?>
1109 </div>
1110 <?php echo $args['after_widget']; ?>
1111 <?php do_action( 'bp_after_following_widget' ); ?>
1112 <?php
1113 }
1114 }
1115 //Callback to save widget settings.
1116 function update( $new_instance, $old_instance ) {
1117 $instance = $old_instance;
1118 $instance['title'] = strip_tags( $new_instance['title'] );
1119 $instance['max_users'] = (int) $new_instance['max_users'];
1120 return $instance;
1121 }
1122 //Widget settings form.
1123 function form( $instance ) {
1124 $instance = wp_parse_args( (array) $instance, array(
1125 'title' => __( "Millionaire's Digest Accounts I've Added to My Feeds", 'buddypress-followers' ),
1126 'max_users' => 16
1127 ) );
1128 ?>
1129 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
1130 <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>
1131 <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>
1132 <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>
1133 <?php
1134 }
1135}
1136add_action( 'widgets_init', create_function( '', 'return register_widget("BP_Millionaires_Digest_Following_Widget");' ) );
1137
1138
1139/* 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 */
1140function millionairesdigest_hide_profile_nav_tabs() {
1141 global $bp;
1142 if ( bp_is_user() && !is_super_admin() ) {
1143 unset($bp->bp_nav['messages']);
1144 unset($bp->bp_nav['notifications']);
1145 unset($bp->bp_nav['checkin']);
1146 unset($bp->bp_nav['following']);
1147 unset($bp->bp_nav['profile-privacy']);
1148 unset($bp->bp_nav['contact']);
1149 unset($bp->bp_options_nav['activity']['following']);
1150 unset($bp->bp_options_nav['activity']['news-feed']);
1151 unset($bp->bp_options_nav['settings']['profile']);
1152 }
1153}
1154add_action('bp_setup_nav', 'millionairesdigest_hide_profile_nav_tabs', 201);
1155
1156
1157/* 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.) */
1158function millionairesdigest_remove_profile_nav_tabs() {
1159 if( bp_is_active( 'xprofile' ) ) :
1160 if ( bp_is_user() && !is_user_logged_in() ) {
1161 bp_core_remove_nav_item( 'checkin' );
1162 bp_core_remove_subnav_item( 'activity', 'following' );
1163 bp_core_remove_subnav_item( 'activity', 'news-feed' );
1164 }
1165 endif;
1166}
1167add_action( 'bp_setup_nav', 'millionairesdigest_remove_profile_nav_tabs', 15 );
1168
1169
1170/* 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.") */
1171function wholeseller_role_cat( $q ) {
1172
1173 // Get the current user
1174 $current_user = wp_get_current_user();
1175
1176 // Displaying only "Wholesale" category products to "whole seller" user role
1177 if ( in_array( 'author', $current_user->roles ) ) {
1178 // Set here the ID for Wholesale category
1179 $q->set( 'tax_query', array(
1180 array(
1181 'taxonomy' => 'product_cat',
1182 'field' => 'term_id',
1183 'terms' => '586965239', // your category ID
1184 )
1185 ) );
1186
1187 // Displaying All products (except "Wholesale" category products)
1188 // to all other users roles (except "wholeseller" user role)
1189 // and to non logged user.
1190 } else {
1191 // Set here the ID for Wholesale category
1192 $q->set( 'tax_query', array(
1193 array(
1194 'taxonomy' => 'product_cat',
1195 'field' => 'term_id',
1196 'terms' => '586965239', // your category ID
1197 'operator' => 'NOT IN'
1198 )
1199 ) );
1200 }
1201}
1202add_action( 'woocommerce_product_query', 'wholeseller_role_cat' );
1203
1204
1205/* Change the "Proceed To Checkout" Button Text */
1206function woocommerce_button_proceed_to_checkout() {
1207 $checkout_url = WC()->cart->get_checkout_url();
1208 ?>
1209 <a href="<?php echo $checkout_url; ?>" class="checkout-button button alt wc-forward"><?php _e( 'Check On Out', 'woocommerce' ); ?></a>
1210 <?php
1211 }
1212
1213
1214/* 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.") */
1215add_filter( 'woocommerce_get_price_html', function( $price, $product ) {
1216 if ( is_admin() ) return $price;
1217 // Hide for these category slugs / IDs
1218 $hide_for_categories = array( '586965238', 'free-magazine-subscription' );
1219 // Don't show price when its in one of the categories
1220 if ( has_term( $hide_for_categories, 'product_cat', $product->get_id() ) ) {
1221 return '';
1222 }
1223 return $price; // Return original price
1224}, 10, 2 );
1225add_filter( 'woocommerce_cart_item_price', '__return_false' );
1226add_filter( 'woocommerce_cart_item_subtotal', '__return_false' );
1227
1228
1229/* Remove the "Related Products" Area After the Single Magazine Pages */
1230remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 10 );
1231
1232
1233/* 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.) */
1234add_filter( 'woocommerce_get_price_html', function( $price ) {
1235 if ( is_admin() ) return $price;
1236 $user = wp_get_current_user();
1237 $hide_for_roles = array( 'author', 'contributor', 'editor' );
1238 // If one of the user roles is in the list of roles to hide for.
1239 if ( array_intersect( $user->roles, $hide_for_roles ) ) {
1240 return ''; // Return empty string to hide.
1241 }
1242 return $price; // Return original price
1243} );
1244add_filter( 'woocommerce_cart_item_price', '__return_false' );
1245add_filter( 'woocommerce_cart_item_subtotal', '__return_false' );
1246
1247
1248/* 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) */
1249function wc_remove_all_quantity_fields( $return, $product ) {
1250 return true;
1251}
1252add_filter( 'woocommerce_is_sold_individually', 'wc_remove_all_quantity_fields', 10, 2 );
1253
1254
1255/* Remove Jetpack Related Posts on Custom Post Type "Products" and on the Custom Post Type's Single Page */
1256function millionairesdigest_jetpack_archive_no_related_posts( $options ) {
1257 if ( is_post_type_archive( 'product' ) ) {
1258 $options['enabled'] = false;
1259 }
1260 return $options;
1261}
1262add_filter( 'jetpack_relatedposts_filter_options', 'millionairesdigest_jetpack_archive_no_related_posts' );
1263function millionairesdigest_jetpack_singular_no_related_posts( $options ) {
1264 if ( is_singular( 'product' ) ) {
1265 $options['enabled'] = false;
1266 }
1267 return $options;
1268}
1269add_filter( 'jetpack_relatedposts_filter_options', 'millionairesdigest_jetpack_singular_no_related_posts' );
1270
1271
1272/* Add a BuddyPress Profile Author Widget for Allowing Us to Display Our User's Profile Fields on Their Posts They Write, Share, Upload, Add, Etc. */
1273class BPDEV_BPAuthorProfile_Widget extends WP_Widget {
1274 public function __construct() {
1275 parent::__construct( false, $name = __( 'BP Author Profile for Blogs', 'blog-author-profile-for-bp' ) );
1276 }
1277 public function widget( $args, $instance ) {
1278 if ( ! bpdev_get_blog_author_id() ) {
1279 return;
1280 }
1281 extract( $args );
1282 echo $args['before_widget'];
1283 echo $args['before_title']
1284 . $instance['title']
1285 . $args['after_title'];
1286 self::bpdev_show_blog_profile( $instance );
1287 /*** show the profile fields**/
1288 echo $args['after_widget'];
1289 }
1290 public function update( $new_instance, $old_instance ) {
1291 $instance = $old_instance;
1292 foreach ( $new_instance as $key => $val ) {
1293 $instance[ $key ] = $val;
1294 }//update the instance
1295 return $instance;
1296 }
1297 public function form( $instance ) {
1298 $instance = wp_parse_args(
1299 (array) $instance,
1300 array(
1301 'title' => __( 'Author Profile', 'blog-author-profile-bp' ),
1302 'show_avatar' => 'yes',
1303 )
1304 );
1305 $title = strip_tags( $instance['title'] );
1306 extract( $instance, EXTR_SKIP );
1307 ?>
1308
1309
1310 <p>
1311 <label for="bpdev-widget-title"><?php _e( 'Title:', 'blog-author-profile-bp' ); ?>
1312 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>"
1313 name="<?php echo $this->get_field_name( 'title' ); ?>" type="text"
1314 value="<?php echo esc_attr( $title ); ?>"/>
1315 </label>
1316 </p>
1317 <p>
1318 <label for="bpdev-widget-show-avatar"><?php _e( 'Show Avatar', 'blog-author-profile-for-bp' ); ?>
1319 <input type="radio" id="<?php echo $this->get_field_id( 'show_avatar' ); ?>"
1320 name="<?php echo $this->get_field_name( 'show_avatar' ); ?>"
1321 value="yes" <?php checked( $instance['show_avatar'], 'yes' ) ; ?> > <?php _e( 'Yes', 'blog-author-profile-for-bp' );?>
1322
1323 <input type="radio" id="<?php echo $this->get_field_id( 'show_avatar' ); ?>"
1324 name="<?php echo $this->get_field_name( 'show_avatar' ); ?>"
1325 value="no" <?php checked( $instance['show_avatar'] , "no" ); ?>> <?php _e( 'No', 'blog-author-profile-for-bp' );?>
1326 </label>
1327 </p>
1328 <?php
1329 //get all xprofile fields and ask user whether to show them or not
1330 ?>
1331 <h3><?php _e( 'Profile Fields Visibility', 'blog-author-profile-for-bp' ); ?></h3>
1332 <table>
1333
1334 <?php if ( function_exists( 'bp_has_profile' ) ) :
1335 if ( bp_has_profile() ) : while ( bp_profile_groups() ) : bp_the_profile_group();
1336 ?>
1337 <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
1338
1339 <?php $fld_name = bp_get_the_profile_field_input_name();
1340 $fld_val = isset( $instance[$fld_name] ) ? $instance[$fld_name] : 'no';//no by default
1341 ?>
1342
1343 <tr>
1344 <td>
1345 <label for="<?php echo $fld_name; ?>"><?php bp_the_profile_field_name() ?></label>
1346
1347 </td>
1348 <td>
1349
1350 <input type="radio" id="<?php echo $this->get_field_id( $fld_name ); ?>"
1351 name="<?php echo $this->get_field_name( $fld_name ); ?>"
1352 value="yes" <?php if ( $fld_val == "yes" ) {
1353 echo "checked='checked'";
1354 } ?> >Show
1355
1356 <input type="radio" id="<?php echo $this->get_field_id( $fld_name ); ?>"
1357 name="<?php echo $this->get_field_name( $fld_name ); ?>"
1358 value="no" <?php if ( $fld_val != "yes" ) {
1359 echo "checked='checked'";
1360 } ?>>Hide
1361
1362 </td>
1363 </tr>
1364
1365 <?php endwhile;
1366 endwhile;
1367 endif;
1368 endif; ?>
1369 </table>
1370
1371 <?php
1372 }
1373//just a hack for now, code can be cleaned later
1374 /**
1375 * @desc Get the admin users of current blog
1376 */
1377 function get_admin_users_for_current_blog() {
1378 $users = get_users(
1379 array(
1380 'role' => 'administrator',
1381 'blog_id' => get_current_blog_id(),
1382 'fields' => 'ID'
1383 )
1384 );
1385 return $users;
1386 }
1387 private static function bpdev_show_blog_profile( $instance ) {
1388 $show_avatar = $instance['show_avatar'];//we need to preserve for multi admin
1389 unset( $instance['show_avatar'] );
1390 unset( $instance['title'] );//unset the title of the widget,because we will be iterating over the instance fields
1391 $author = bpdev_get_blog_author_id();
1392 if ( empty( $author ) ) {
1393 return;
1394 }
1395 $user_id = $author;
1396 $op = '<table class="my-blog-profile">';
1397 if ( $show_avatar == 'yes' ) {
1398 $op .= '<tr class="user-avatar"><td>' . bp_core_get_userlink( $user_id ) . '</td>';
1399 $op .= '<td>' . bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb' ) ) . '</td></tr>';
1400 }
1401 //bad approach, because buddypress does not allow to fetch the field name from field key
1402 if ( function_exists( 'bp_has_profile' ) ) :
1403 if ( bp_has_profile( 'user_id=' . $user_id ) ) :
1404 while ( bp_profile_groups() ) : bp_the_profile_group();
1405 while ( bp_profile_fields() ) : bp_the_profile_field();
1406 $fld_name = bp_get_the_profile_field_input_name();
1407 if ( array_key_exists( $fld_name, $instance ) && $instance[ $fld_name ] == 'yes' ) {
1408 $op .= '<tr><p>' . bp_get_profile_field_data( array(
1409 'field' => bp_get_the_profile_field_id(),
1410 'user_id' => $user_id
1411 ) ) . '</p></tr>';
1412 }
1413 endwhile;
1414 endwhile;
1415 endif;
1416 endif;
1417 $op .= '</table>';
1418 echo $op;
1419 }
1420}
1421/** Let us register the widget*/
1422function bp_blog_authorprofile_register_widget() {
1423 register_widget( 'BPDEV_BPAuthorProfile_Widget' );
1424}
1425add_action( 'bp_widgets_init', 'bp_blog_authorprofile_register_widget' );
1426/**
1427 * Get the author Id for current page/post
1428 */
1429function bpdev_get_blog_author_id() {
1430 //if this is a single user blog, admin will not need this widgets as Bp profile for blogs will do that
1431 $author_id = null;
1432 if ( in_the_loop() ) {
1433 //inside post loop
1434 $author_id = get_the_author_meta('ID');
1435 } elseif ( is_singular() && ! is_buddypress() ) {
1436 global $wp_the_query;
1437 $author_id = $wp_the_query->posts[0]->post_author;
1438 } elseif ( is_author() ) {
1439 global $wp_the_query;
1440 $author_id = $wp_the_query->get_queried_object_id();
1441 }
1442 return $author_id;
1443}
1444
1445
1446/* 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 */
1447function bpew_load(){
1448 // Display our own fields
1449 add_action('in_widget_form', 'bpew_extend_form', 10, 3);
1450 // Save our new things
1451 add_filter('widget_update_callback', 'bpew_extend_update', 10, 4);
1452 // Display content if needed
1453 add_filter('widget_display_callback', 'bpew_extend_display', 10, 3);
1454}
1455function bpew_extend_form($class, $return, $instance){
1456 echo '<hr /><p>'.__('Display the widget if it satisfies one or more of the BuddyPress-specific options below:','bpew').'</p>';
1457 if(!isset($instance['bp_component_type']))
1458 $instance['bp_component_type'] = '';
1459 if(!isset($instance['bp_component_ids']))
1460 $instance['bp_component_ids'] = '';
1461 echo '<p>
1462 <input '.checked($instance['bp_component_type'], '', false).' type="radio" name="'.$class->get_field_name('bp_component_type').'" value=""/> '.__('Do not apply', 'bpew').'<br />
1463 <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 />
1464 <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 />
1465 <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 />
1466 <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 />
1467 <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 />
1468 <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 />
1469 <input '.checked($instance['bp_component_type'], 'members', false).' type="radio" name="'.$class->get_field_name('bp_component_type').'" value="members"/> '.__('Members (Single)', 'bpew').'<br />
1470 <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 />
1471 <input '.checked($instance['bp_component_type'], 'groups', false).' type="radio" name="'.$class->get_field_name('bp_component_type').'" value="groups"/> '.__('Groups (Single)', 'bpew').'<br />
1472 <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').'
1473 </p>';
1474 echo '<p>
1475 <label id="'.$class->get_field_id('bp_component_ids').'">'.__('IDs','bpew').':</label>
1476 <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 />
1477 <span class="description">'.__('Use commas to separate; No spaces.','bpew').'</span>
1478 </p>';
1479 add_action('bpew_extend_form', $class, $return, $instance);
1480 return $return;
1481}
1482function bpew_extend_update($instance, $new_instance, $old_instance, $this){
1483 $new_instance = apply_filters('bpew_extend_update', $new_instance, $old_instance, $instance, $this);
1484 return $new_instance;
1485}
1486function bpew_extend_display($instance, $this, $args){
1487 if(empty($instance['bp_component_type']))
1488 return $instance;
1489 global $bp;
1490 $user_id = bp_displayed_user_id();
1491 // Display on profile pages with the "User" member type
1492 if($instance['bp_component_type'] == 'member_typea' && bp_displayed_user_id() && bp_has_member_type( $user_id, 'user' )
1493 && in_array(bp_has_member_type(), explode(',', $instance['bp_component_ids']))){
1494 return $instance;
1495 }
1496 // Display on profile pages with the "Brand" member type
1497 if($instance['bp_component_type'] == 'member_typeb' && bp_displayed_user_id() && bp_has_member_type( $user_id, 'brand' )
1498 && in_array(bp_has_member_type(), explode(',', $instance['bp_component_ids']))){
1499 return $instance;
1500 }
1501 // Display on profile pages with the "Famous Person" member type
1502 if($instance['bp_component_type'] == 'member_typec' && bp_displayed_user_id() && bp_has_member_type( $user_id, 'famous-person' )
1503 && in_array(bp_has_member_type(), explode(',', $instance['bp_component_ids']))){
1504 return $instance;
1505 }
1506 // Display on profile pages with the "Organization" member type
1507 if($instance['bp_component_type'] == 'member_typed' && bp_displayed_user_id() && bp_has_member_type( $user_id, 'organization' )
1508 && in_array(bp_has_member_type(), explode(',', $instance['bp_component_ids']))){
1509 return $instance;
1510 }
1511 // Display on profile pages with the "Millionaire's Digest" member type
1512 if($instance['bp_component_type'] == 'member_typee' && bp_displayed_user_id() && bp_has_member_type( $user_id, 'millionaires-digest' )
1513 && in_array(bp_has_member_type(), explode(',', $instance['bp_component_ids']))){
1514 return $instance;
1515 }
1516 // Display on profile pages with the "Government" member type
1517 if($instance['bp_component_type'] == 'member_typef' && bp_displayed_user_id() && bp_has_member_type( $user_id, 'government' )
1518 && in_array(bp_has_member_type(), explode(',', $instance['bp_component_ids']))){
1519 return $instance;
1520 }
1521 // Display on specific profile pages
1522 if($instance['bp_component_type'] == 'members' && bp_displayed_user_id()
1523 && in_array(bp_displayed_user_id(), explode(',', $instance['bp_component_ids']))){
1524 return $instance;
1525 }
1526 if($instance['bp_component_type'] == 'members_dir' && bp_is_directory() && bp_current_component() == BP_MEMBERS_SLUG){
1527 return $instance;
1528 }
1529 // Display on groups pages only
1530 $group_id = $bp->groups->current_group->id;
1531 if($instance['bp_component_type'] == 'groups' && !empty($group_id)
1532 && in_array($group_id, explode(',', str_replace(' ', '', trim($instance['bp_component_ids']))))){
1533 return $instance;
1534 }
1535 if($instance['bp_component_type'] == 'groups_dir' && bp_is_directory() && bp_current_component() == BP_GROUPS_SLUG){
1536 return $instance;
1537 }
1538 return false;
1539}
1540add_action('bp_init', 'bpew_load');
1541
1542
1543/* BuddyPress Total Friends Count */
1544class Total_Friends_Widget extends WP_Widget {
1545 public function __construct() {
1546 $widget_ops = array('classname' => 'Total_Friends_Widget', 'description' => 'Display the total number of friends a displayed user has on their profile as a widget.' );
1547 $this->WP_Widget('Total_Friends_Widget', 'BuddyPress Total Friends Count', $widget_ops);
1548 }
1549 function widget($args, $instance) {
1550 // PART 1: Extracting the arguments + getting the values
1551 extract($args, EXTR_SKIP);
1552 $title = empty( $instance['title'] ) ? ' ' : apply_filters('widget_title', $instance['title']);
1553 $subject_single = __( 'person' , 'Total_Friends_Widget' );
1554 $subject_plural = __( 'people' , 'Total_Friends_Widget' );
1555 $count = friends_get_friend_count_for_user( bp_displayed_user_id() );
1556 // Before widget code, if any
1557 echo (isset($before_widget)?$before_widget:'');
1558 // PART 2: The title and the text output
1559 if (!empty($title) )
1560 echo $before_title . $title . $after_title;
1561 if( $count == 0 ) {
1562 echo '<p/>' . $count . ' ' . $subject_plural . '<p/>';
1563 }
1564 if( $count == 1 ) {
1565 echo '<p/>' . $count . ' ' . $subject_single . '<p/>';
1566 }
1567 if( $count > 1 ) {
1568 echo '<p/>' . $count['followers'] . ' ' . $subject_plural . '<p/>';
1569 }
1570 // After widget code, if any
1571 echo (isset($after_widget)?$after_widget:'');
1572 }
1573
1574 public function form( $instance ) {
1575 // PART 1: Extract the data from the instance variable
1576 $instance = wp_parse_args( (array) $instance, array( 'title' => 'Total Friends' ) );
1577 $title = $instance['title'];
1578 // PART 2-3: Display the fields
1579 ?>
1580 <!-- PART 2: Widget Title field START -->
1581 <p>
1582 <label for="<?php echo $this->get_field_id('title'); ?>">Title:
1583 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
1584 name="<?php echo $this->get_field_name('title'); ?>" type="text"
1585 value="<?php echo attribute_escape($title); ?>" />
1586 </label>
1587 </p>
1588 <!-- Widget Title field END -->
1589 <?php
1590 }
1591
1592 function update($new_instance, $old_instance) {
1593 $instance = $old_instance;
1594 $instance['title'] = $new_instance['title'];
1595 return $instance;
1596 }
1597}
1598add_action( 'widgets_init', create_function('', 'return register_widget("Total_Friends_Widget");') );
1599
1600
1601/* BuddyPress Total Followers Count Widget */
1602class Total_Followers_Widget extends WP_Widget {
1603 public function __construct() {
1604 $widget_ops = array('classname' => 'Total_Followers_Widget', 'description' => 'Display the total number of followers a displayed user has on their profile as a widget.' );
1605 $this->WP_Widget('Total_Followers_Widget', 'BuddyPress Total Followers Count', $widget_ops);
1606 }
1607 function widget($args, $instance) {
1608 // PART 1: Extracting the arguments + getting the values
1609 extract($args, EXTR_SKIP);
1610 $title = empty( $instance['title'] ) ? ' ' : apply_filters('widget_title', $instance['title']);
1611 $subject_single = __( 'person' , 'Total_Followers_Widget' );
1612 $subject_plural = __( 'people' , 'Total_Followers_Widget' );
1613 // Before widget code, if any
1614 echo (isset($before_widget)?$before_widget:'');
1615 // PART 2: The title and the text output
1616 if (!empty($title) )
1617 echo $before_title . $title . $after_title;
1618 $count = bp_follow_total_follow_counts( array(
1619 'user_id' =>bp_displayed_user_id() ) );
1620 if( $count['followers'] == 0 ) {
1621 echo '<p/>' . $count['followers'] . ' ' . $subject_plural . '<p/>';
1622 }
1623 if( $count['followers'] == 1 ) {
1624 echo '<p/>' . $count['followers'] . ' ' . $subject_single . '<p/>';
1625 }
1626 if( $count['followers'] > 1 ) {
1627 echo '<p/>' . $count['followers'] . ' ' . $subject_plural . '<p/>';
1628 }
1629 // After widget code, if any
1630 echo (isset($after_widget)?$after_widget:'');
1631 }
1632
1633 public function form( $instance ) {
1634 // PART 1: Extract the data from the instance variable
1635 $instance = wp_parse_args( (array) $instance, array( 'title' => 'Total Followers' ) );
1636 $title = $instance['title'];
1637 // PART 2-3: Display the fields
1638 ?>
1639<!-- PART 2: Widget Title field START -->
1640<p>
1641 <label for="<?php echo $this->get_field_id('title'); ?>">Title:
1642 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
1643 name="<?php echo $this->get_field_name('title'); ?>" type="text"
1644 value="<?php echo attribute_escape($title); ?>" />
1645 </label>
1646</p>
1647<!-- Widget Title field END -->
1648<!-- PART 3: Widget Text field START -->
1649
1650<!-- Widget Text field END -->
1651<?php
1652 }
1653 function update($new_instance, $old_instance) {
1654 $instance = $old_instance;
1655 $instance['title'] = $new_instance['title'];
1656 $instance['text'] = $new_instance['text'];
1657 return $instance;
1658 }
1659}
1660add_action( 'widgets_init', create_function('', 'return register_widget("Total_Followers_Widget");') );
1661
1662
1663/* 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! ) */
1664//Add the "About Me Bio" Profile Field to the Member Directoy
1665function my_directory() {
1666if ( bp_is_active( 'xprofile' ) )
1667 if ( $aboutme = xprofile_get_field_data( 'About Me', bp_get_member_user_id() ) ) :
1668 echo '<br/><div class="About_Me">';
1669 echo $aboutme;
1670 echo '</div>';
1671 endif;
1672}
1673add_filter ( 'bp_directory_members_item', 'my_directory' );
1674
1675
1676/* Add a BuddyPess Profile Fields Widget for Allowing Us to Display User's Profile Fields as a Widget */
1677class BPDev_BPProfile_Widget extends WP_Widget {
1678 public function __construct() {
1679 parent::__construct( false, $name = __( 'BuddyPress User Info', 'bp-profile-widget-for-blogs' ) );
1680 }
1681 public function widget( $args, $instance ) {
1682 echo $before_widget;
1683 echo $before_title
1684 . $instance['title']
1685 . $after_title;
1686 self::show_blog_profile( $instance );
1687 echo $after_widget;
1688 }
1689 public function update( $new_instance, $old_instance ) {
1690 $instance = $old_instance;
1691 foreach ( $new_instance as $key => $val ) {
1692 $instance[ $key ] = $val;//update the instance
1693 }
1694 return $instance;
1695 }
1696 public function form( $instance ) {
1697 $instance = wp_parse_args( (array) $instance, array(
1698 'title' => __( '', 'bp-profile-widget-for-blogs' )
1699 ) );
1700 $title = strip_tags( $instance['title'] );
1701 extract( $instance, EXTR_SKIP );
1702 ?>
1703 <p>
1704 <label for="bpdev-widget-title">
1705 <?php _e( 'Title:', 'bp-profile-widget-for-blogs' ); ?>
1706 <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 ) ); ?>"/>
1707 </label>
1708 </p>
1709 <?php
1710 //get all xprofile fields and ask user whether to show them or not
1711 ?>
1712 <h3><?php _e( 'Profile Fields Visibility', 'bp-profile-widget-for-blogs' ); ?></h3>
1713 <table>
1714 <?php if ( function_exists( 'bp_has_profile' ) ) : if ( bp_has_profile() ) : while ( bp_profile_groups() ) : bp_the_profile_group(); ?>
1715 <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
1716 <?php $fld_name = bp_get_the_profile_field_input_name();
1717 $fld_val = isset( ${$fld_name} ) ? ${$fld_name} : 'no';
1718 ?>
1719 <tr>
1720 <td>
1721 <label for="<?php echo $fld_name; ?>"><?php bp_the_profile_field_name() ?></label>
1722 </td>
1723 <td>
1724 <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
1725 <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
1726 </td>
1727 </tr>
1728 <?php endwhile;
1729 endwhile;
1730 endif;
1731 endif; ?>
1732 </table>
1733 <?php
1734 }
1735 public static function get_users( $user_role = null ) {
1736 $bp_displayed_user_id = bp_displayed_user_id();
1737 return $bp_displayed_user_id;
1738 }
1739 public static function show_blog_profile( $instance ) {
1740 //if buddypress is not active, return
1741 if ( ! function_exists( 'buddypress' ) ) {
1742 return;
1743 }
1744 unset( $instance['title'] );//unset the title of the widget,because we will be iterating over the instance fields
1745 if ( bp_is_user() ) {
1746 $bp_displayed_user_id = array( bp_displayed_user_id() );
1747 }
1748 if ( empty( $bp_displayed_user_id ) ) {
1749 return;
1750 //Do not display the widget if profile field is empty
1751 }
1752 foreach ( $bp_displayed_user_id as $user ) {
1753 $user_id = $user;//["user_id"];
1754 $op = "<table class='my-blog-profile bp-blog-user-profile bp-blog-user-profile-{$user}'>";
1755 //bad approach, because buddypress does not allow to fetch the field name from field key
1756 if ( function_exists( 'bp_has_profile' ) ) :
1757 if ( bp_has_profile( 'user_id=' . $user_id ) ) :
1758 while ( bp_profile_groups() ) : bp_the_profile_group();
1759 while ( bp_profile_fields() ) : bp_the_profile_field();
1760 $fld_name = bp_get_the_profile_field_input_name();
1761 if ( array_key_exists( $fld_name, $instance ) && $instance[ $fld_name ] == 'yes' ) {
1762 $op .= '<tr><h4 class="bp_profile_field_widget_data_title">' . bp_get_the_profile_field_name() . '</h4><p class="bp_profile_field_widget_data">' .xprofile_get_field_data( bp_get_the_profile_field_id(),$user_id, 'comma' ) . '</p></tr>';
1763 }
1764 endwhile;
1765 endwhile;
1766 endif;
1767 endif;
1768 $op .= "</table>";
1769 echo $op;
1770 }
1771 }
1772}
1773/** Let us register the widget*/
1774function bpdev_register_bpprofile_for_blogs_widgets() {
1775 register_widget( 'BPDev_BPProfile_Widget' );
1776}
1777add_action( 'bp_widgets_init', 'bpdev_register_bpprofile_for_blogs_widgets' );
1778
1779
1780
1781/* 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. */
1782function millionairesdigest_redirect_on_first_login( $url, $request, $user ) {
1783 $last_activity = bp_get_user_last_activity( $user->ID );
1784 if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
1785 if( $user->has_cap( 'user' ) && empty( $last_activity ) ) {
1786 $url = home_url('/users-welcome-page/');
1787 } else {
1788 if( $user->has_cap( 'contributor' ) && empty( $last_activity ) ) {
1789 $url = home_url('/welcome-contributors-page/');
1790 } else {
1791 if( $user->has_cap( 'author' ) && empty( $last_activity ) ) {
1792 $url = home_url('/welcome-authors-page/');
1793 } else {
1794 if( $user->has_cap( 'editor' ) && empty( $last_activity ) ) {
1795 $url = home_url('/welcome-editor-page/');
1796 } else {
1797 if( $user->has_cap( 'photographer' ) && empty( $last_activity ) ) {
1798 $url = home_url('/welcome-photographers-page/');
1799 } else {
1800 if( $user->has_cap( 'publisher' ) && empty( $last_activity ) ) {
1801 $url = home_url('/welcome-publishers-page/');
1802 } else {
1803 if( $user->has_cap( 'magazine-author' ) && empty( $last_activity ) ) {
1804 $url = home_url('/welcome-magazine-authors-page/');
1805 } else {
1806 if( $user->has_cap( 'magazine-editor' ) && empty( $last_activity ) ) {
1807 $url = home_url('/welcome-magazine-editors-page/');
1808 } else {
1809 if( $user->has_cap( 'magazine-photographer' ) && empty( $last_activity ) ) {
1810 $url = home_url('/welcome-magazine-photographers-page/');
1811 } else {
1812 if( $user->has_cap( 'magazine-designer' ) && empty( $last_activity ) ) {
1813 $url = home_url('/welcome-magazine-designers-page/');
1814 } else {
1815 if( $user->has_cap( 'magazine-publisher' ) && empty( $last_activity ) ) {
1816 $url = home_url('/welcome-magazine-publishers-page/');
1817 } else {
1818 if( $user->has_cap( 'brand-account' ) && empty( $last_activity ) ) {
1819 $url = home_url('/welcome-brand-accounts-page/');
1820 } else {
1821 if( $user->has_cap( 'famous-person-account' ) && empty( $last_activity ) ) {
1822 $url = home_url('/welcome-famous-people-accounts-page/');
1823 } else {
1824 if( $user->has_cap( 'organization-account' ) && empty( $last_activity ) ) {
1825 $url = home_url('/welcome-organization-accounts-page/');
1826 } else {
1827 $url = home_url('/activity-wall/');
1828 }
1829 }
1830 }
1831 }
1832 }
1833 }
1834 }
1835 }
1836 }
1837 }
1838 }
1839 }
1840 }
1841 }
1842 }
1843 return $url;
1844}
1845add_filter('login_redirect', 'millionairesdigest_redirect_on_first_login', 10, 3 );
1846
1847
1848/* 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) */
1849add_action( 'wp_logout', create_function( '', 'wp_redirect( home_url() ); exit();' ) );
1850
1851
1852/* 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 */
1853function set_default_member_type( $user_id, $user_login, $user_password, $user_email, $usermeta ) {
1854 bp_set_member_type( $user_id, 'user' );
1855}
1856add_action( 'bp_core_signup_user', 'set_default_member_type', 10, 5 );
1857
1858
1859/* Auto Join All New Team & Company Members to Groups Based on Their Role After Creating Their Account and Logging in for the First Time */
1860function auto_join_contributors_to_groups( $user_id, $role, $old_roles ) {
1861 if( $role == 'contributor' ) {
1862 groups_accept_invite( $user_id, 1 );
1863 groups_accept_invite( $user_id, 11 );
1864 groups_accept_invite( $user_id, 13 );
1865 }
1866}
1867add_action( 'set_user_role', 'auto_join_contributors_to_groups', 11, 3 );
1868function auto_join_photographers_to_groups( $user_id, $role, $old_roles ) {
1869 if( $role == 'photographer' ) {
1870 groups_accept_invite( $user_id, 2 );
1871 groups_accept_invite( $user_id, 11 );
1872 groups_accept_invite( $user_id, 13 );
1873 }
1874}
1875add_action( 'set_user_role', 'auto_join_photographers_to_groups', 11, 3 );
1876function auto_join_authors_to_groups( $user_id, $role, $old_roles ) {
1877 if( $role == 'author' ) {
1878 groups_accept_invite( $user_id, 3 );
1879 groups_accept_invite( $user_id, 11 );
1880 groups_accept_invite( $user_id, 13 );
1881 }
1882}
1883add_action( 'set_user_role', 'auto_join_authors_to_groups', 11, 3 );
1884function auto_join_editors_to_groups( $user_id, $role, $old_roles ) {
1885 if( $role == 'editor' ) {
1886 groups_accept_invite( $user_id, 4 );
1887 groups_accept_invite( $user_id, 11 );
1888 groups_accept_invite( $user_id, 13 );
1889 }
1890}
1891add_action( 'set_user_role', 'auto_join_editors_to_groups', 11, 3 );
1892function auto_join_publishers_to_groups( $user_id, $role, $old_roles ) {
1893 if( $role == 'publisher' ) {
1894 groups_accept_invite( $user_id, 5 );
1895 groups_accept_invite( $user_id, 11 );
1896 groups_accept_invite( $user_id, 13 );
1897 }
1898}
1899add_action( 'set_user_role', 'auto_join_publishers_to_groups', 11, 3 );
1900function auto_join_magazine_authors_to_groups( $user_id, $role, $old_roles ) {
1901 if( $role == 'magazine-author' ) {
1902 groups_accept_invite( $user_id, 6 );
1903 groups_accept_invite( $user_id, 12 );
1904 groups_accept_invite( $user_id, 13 );
1905 }
1906}
1907add_action( 'set_user_role', 'auto_join_magazine_authors_to_groups', 11, 3 );
1908function auto_join_magazine_photographers_to_groups( $user_id, $role, $old_roles ) {
1909 if( $role == 'magazine-photographer' ) {
1910 groups_accept_invite( $user_id, 7 );
1911 groups_accept_invite( $user_id, 12 );
1912 groups_accept_invite( $user_id, 13 );
1913 }
1914}
1915add_action( 'set_user_role', 'auto_join_magazine_photographers_to_groups', 11, 3 );
1916function auto_join_magazine_editors_to_groups( $user_id, $role, $old_roles ) {
1917 if( $role == 'magazine-editor' ) {
1918 groups_accept_invite( $user_id, 8 );
1919 groups_accept_invite( $user_id, 12 );
1920 groups_accept_invite( $user_id, 13 );
1921 }
1922}
1923add_action( 'set_user_role', 'auto_join_magazine_editors_to_groups', 11, 3 );
1924function auto_join_magazine_designers_to_groups( $user_id, $role, $old_roles ) {
1925 if( $role == 'magazine-designer' ) {
1926 groups_accept_invite( $user_id, 9 );
1927 groups_accept_invite( $user_id, 12 );
1928 groups_accept_invite( $user_id, 13 );
1929 }
1930}
1931add_action( 'set_user_role', 'auto_join_magazine_designers_to_groups', 11, 3 );
1932function auto_join_magazine_publishers_to_groups( $user_id, $role, $old_roles ) {
1933 if( $role == 'magazine-publisher' ) {
1934 groups_accept_invite( $user_id, 10 );
1935 groups_accept_invite( $user_id, 12 );
1936 groups_accept_invite( $user_id, 13 );
1937 }
1938}
1939add_action( 'set_user_role', 'auto_join_magazine_publishers_to_groups', 11, 3 );
1940
1941
1942/* 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 */
1943function bpfr_guest_redirect() {
1944 global $bp;
1945 // Enter the slug or component conditional here
1946 if ( bp_is_members_directory() ) {
1947 // Not logged in user are redirected to - comment/uncomment or add/remove to your need
1948 if( !is_user_logged_in() ) {
1949 wp_redirect( get_option('siteurl') ); //back to homepage
1950 }
1951 }
1952}
1953add_filter( 'get_header', 'bpfr_guest_redirect', 1 );
1954
1955
1956/* Rename All of the Following Subnav Tabs in User's Messages */
1957function change_profile_submenu_tabs(){
1958 global $bp;
1959 $bp->bp_options_nav['messages']['inbox']['name'] = 'All Messages';
1960 $bp->bp_options_nav['messages']['starred']['name'] = 'Liked Messages';
1961 $bp->bp_options_nav['messages']['sentbox']['name'] = 'Sent Messages';
1962 $bp->bp_options_nav['messages']['compose']['name'] = 'New Message';
1963 $bp->bp_options_nav['settings']['notifications']['name'] = 'Email Notifications';
1964}
1965add_action('bp_setup_nav', 'change_profile_submenu_tabs', 999);
1966
1967
1968/* Remove the "Sent" Messages Subnav Tab in Users Profiles as It is Not Neccessary and Helps Keep the Inbox More Clear for Our Users */
1969function md_remove_sent_messages_subnav_tab() {
1970 if ( is_super_admin() ) {
1971 return;
1972 }
1973 global $bp;
1974 if ( $bp->current_component == $bp->messages->slug ) {
1975 bp_core_remove_subnav_item( $bp->messages->slug, 'sentbox' );
1976 }
1977}
1978add_action( 'wp', 'md_remove_sent_messages_subnav_tab', 2 );
1979
1980
1981/* Add the "Matchmaker Bio" Profile Field to Users Profiles in the Member Directory for the Purpose of Giving People the Ability to Connect More */
1982function show_extra_profile_fields_in_members_directory() {
1983 $bio = bp_get_member_profile_data('field=Bio');
1984 if ($bio) {
1985 echo '<div class="mdetcenter">'. $bio . '</div>';
1986 }
1987}
1988add_action('bp_directory_members_item', 'show_extra_profile_fields_in_members_directory');
1989
1990
1991/* Disable the WYSIWYG Editor from User's Profile Fields */
1992function bp_disable_richtext($enabled, $field_id) {
1993 $enabled = false;
1994 return $enabled;
1995}
1996add_filter('bp_xprofile_is_richtext_enabled_for_field', 'bp_disable_richtext', 10, 2);
1997
1998
1999/* Remove the Private Message Button from the Member Directory, Friends Lists, Groups Lists, Etc. by Allowing It to Only Be Displayed if a Logged-In User is Viewing or on Another User's Profile */
2000function show_private_message_button( $button ) {
2001 if ( bp_is_active( 'xprofile' ) && bp_is_user() ) {
2002 return $button;
2003 }
2004 }
2005add_filter( 'bp_get_send_message_button', 'show_private_message_button', 1 , 1 );
2006
2007
2008/* Add a BuddyPress User Groups Widget for Allowing Us to Display the Groups in Which a Displayed User is a Part of as a Widget */
2009class BP_Extended_User_Groups_Widget extends WP_Widget {
2010 public function __construct() {
2011 $widget_ops = array(
2012 'description' => __( 'A Dynamic list of groups of created, joined by the logged in user and control to show no. of groups', 'bp-extended-user-groups-widget' ),
2013 );
2014 parent::__construct( false, _x( 'BuddyPress Extended User Groups', 'widget name', 'bp-extended-user-groups-widget' ), $widget_ops );
2015 }
2016 public function widget( $args, $instance ) {
2017 extract( $args );
2018 $user_id = bp_displayed_user_id();
2019 $list_type = $instance['list_type'];
2020 //type: active,random etc
2021 if ( empty( $instance['type'] ) ) {
2022 $instance['type'] = 'popular';
2023 }
2024 if ( empty( $instance['order'] ) ) {
2025 $instance['order'] = 'ASC';
2026 }
2027 if ( empty( $instance['limit'] ) ) {
2028 $instance['limit'] = 5;
2029 }
2030 if ( empty( $instance['title'] ) ) {
2031 $instance['title'] = __( 'My Groups', 'bp-extended-user-groups-widget' );
2032 }
2033 $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
2034 echo $before_widget;
2035 echo $before_title . $title . $after_title;
2036 $group_args = array(
2037 'user_id' => $user_id,
2038 'type' => $instance['type'],
2039 'order' => $instance['order'],
2040 'per_page' => $instance['limit'],
2041 'max' => $instance['limit'],
2042 );
2043 //modify list for groups when we need t list all groups of which the current user is admin
2044 if ( $list_type == 'admin' ) {
2045 unset( $group_args['user_id'] );
2046 $groups = BP_Groups_Member::get_is_admin_of( $user_id, $instance['limit'] );
2047 $groups = $groups['groups'];
2048 $group_ids = wp_list_pluck( $groups, 'id' );
2049 if ( empty( $group_ids ) ) {
2050 $group_ids = array( 0, 0 );
2051 }
2052 $group_args['include'] = $group_ids;
2053 }
2054 $group_args['show_hidden'] = true;//show hidden groups too
2055 ?>
2056 <?php if ( bp_has_groups( $group_args ) ) : ?>
2057 <ul id="extended-groups-list" class="item-list">
2058 <?php while ( bp_groups() ) : bp_the_group(); ?>
2059 <li <?php bp_group_class( array( 'bp-extended-user-groups-widget-item bp-extended-groups-clearfix' ) ); ?>>
2060 <div class="item-avatar">
2061 <a href="<?php bp_group_permalink() ?>"
2062 title="<?php bp_group_name() ?>"><?php bp_group_avatar_thumb() ?></a>
2063 </div>
2064 <div class="item">
2065 <div class="item-title">
2066 <a href="<?php bp_group_permalink() ?>" title="<?php bp_group_name() ?>"><?php bp_group_name() ?></a>
2067 </div>
2068 <div class="item-meta">
2069 <span class="activity">
2070 <?php
2071 if ( 'newest' == $instance['type'] ) {
2072 printf( __( 'created %s', 'bp-extended-user-groups-widget' ), bp_get_group_date_created() );
2073 } elseif ( 'active' == $instance['type'] ) {
2074 printf( __( 'active %s', 'bp-extended-user-groups-widget' ), bp_get_group_last_active() );
2075 } elseif ( 'popular' == $instance['type'] ) {
2076 bp_group_member_count();
2077 }
2078 ?>
2079 </span>
2080 </div>
2081 </div>
2082 </li>
2083 <?php endwhile; ?>
2084 </ul>
2085 <?php wp_nonce_field( 'groups_widget_groups_list', '_wpnonce-groups' ); ?>
2086 <input type="hidden" name="groups_widget_max" id="groups_widget_max" value="<?php echo esc_attr( $instance['limit'] ); ?>"/>
2087 <?php else: ?>
2088 <div class="widget-error">
2089 <?php _e( 'Sorry, no groups were found.', 'bp-extended-user-groups-widget' ) ?>
2090 </div>
2091 <?php endif; ?>
2092 <style type="text/css">
2093 .bp-extended-groups-clearfix:after {
2094 content:"";
2095 display:table;
2096 clear:both;
2097 }
2098 #extended-groups-list{
2099 list-style: none;
2100 margin-left:0;
2101 }
2102 </style>
2103 <?php echo $after_widget; ?>
2104 <?php
2105 }
2106 public function update( $new_instance, $old_instance ) {
2107 $instance = $old_instance;
2108 $instance['title'] = strip_tags( $new_instance['title'] );
2109 $instance['type'] = $new_instance['type'];
2110 $instance['order'] = $new_instance['order'];
2111 $instance['limit'] = $new_instance['limit'];
2112 $instance['list_type'] = $new_instance['list_type'];
2113 return $instance;
2114 }
2115 public function form( $instance ) {
2116 $defaults = array(
2117 'title' => __( 'Your Groups', 'bp-extended-user-groups-widget' ),
2118 'list_type' => 'member',
2119 'type' => 'active',
2120 'order' => 'ASC',
2121 'limit' => 5,
2122 );
2123 $instance = wp_parse_args( (array) $instance, $defaults );
2124 $title = strip_tags( $instance['title'] );
2125 $limit = strip_tags( $instance['limit'] );
2126 $type = strip_tags( $instance['type'] );
2127 $order = strip_tags( $instance['order'] );
2128 $list_type = $instance['list_type'];
2129 ?>
2130 <p>
2131 <label for="<?php echo $this->get_field_id( 'title' ); ?>">
2132 <?php _e( 'Title:', 'bp-extended-user-groups-widget' ); ?>
2133 <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( $title ); ?>" style="width: 100%"/>
2134 </label>
2135 </p>
2136 <p>
2137 <label for="<?php echo $this->get_field_id( 'list_type' ); ?>">
2138 <?php _e( 'List Groups of which user is:', 'bp-extended-user-groups-widget' ); ?>
2139 </label>
2140 <label>
2141 <input name="<?php echo $this->get_field_name( 'list_type' ); ?>" type="radio" value="member" <?php checked( $list_type, 'member' ); ?> /> <?php _e( 'Member', 'bp-extended-user-groups-widget' );?>
2142 </label>
2143 <label>
2144 <input name="<?php echo $this->get_field_name( 'list_type' ); ?>" type="radio" value="admin" <?php checked( $list_type, 'admin' ); ?> /> <?php _e( 'Admin', 'bp-extended-user-groups-widget'); ?>
2145 </label>
2146 </p>
2147 <p>
2148 <label for="<?php echo $this->get_field_id( 'type' ); ?>">
2149 <?php _e( 'List Type', 'bp-extended-user-groups-widget' ); ?>
2150 </label>
2151 <select name="<?php echo $this->get_field_name( 'type' ); ?>" id="<?php echo $this->get_field_id( 'type' ); ?>">
2152 <option value="active" <?php selected( 'active', $type, true ) ?>>
2153 <?php _e( 'Most Recent Active', 'bp-extended-user-groups-widget' ) ?>
2154 </option>
2155 <option value="popular" <?php selected( 'popular', $type, true ) ?>>
2156 <?php _e( 'Most Popular', 'bp-extended-user-groups-widget' ) ?>
2157 </option>
2158 <option value="alphabetical" <?php selected( 'alphabetical', $type, true ) ?>>
2159 <?php _e( 'Alphabetical', 'bp-extended-user-groups-widget' ) ?>
2160 </option>
2161 <option value="newest" <?php selected( 'newest', $type, true ) ?>>
2162 <?php _e( 'New Groups', 'bp-extended-user-groups-widget' ) ?>
2163 </option>
2164 <option value="random" <?php selected( 'random', $type, true ) ?>>
2165 <?php _e( 'Random', 'bp-extended-user-groups-widget' ) ?>
2166 </option>
2167
2168 </select>
2169 </p>
2170 <p>
2171 <label for="<?php echo $this->get_field_id( 'order' ); ?>">
2172 <?php _e( 'Order', 'bp-extended-user-groups-widget' ); ?>
2173 </label>
2174 <select name="<?php echo $this->get_field_name( 'order' ); ?>" id="<?php echo $this->get_field_id( 'order' ); ?>">
2175 <option value="ASC" <?php selected( 'ASC', $order, true ) ?>>
2176 <?php _e( 'Ascending Order', 'bp-extended-user-groups-widget' ) ?>
2177 </option>
2178 <option value="DESC" <?php selected( 'DESC', $order, true ) ?>>
2179 <?php _e( 'Descending Order', 'bp-extended-user-groups-widget' ) ?>
2180 </option>
2181 </select>
2182 </p>
2183 <p>
2184 <label for="<?php echo $this->get_field_id( 'limit' ); ?>">
2185 <?php _e( 'Limit Group To Show:', 'bp-extended-user-groups-widget' ); ?>
2186 <input id="<?php echo $this->get_field_name( 'limit' ); ?>" name="<?php echo $this->get_field_name( 'limit' ); ?>" type="text" value="<?php echo esc_attr( $limit ); ?>" style="width: 30%" />
2187 </label>
2188 </p>
2189 <?php
2190 }
2191}
2192Class BP_Extended_User_Groups_Widget_Helper {
2193 private static $instance;
2194 private $path;
2195 private function __construct() {
2196 $this->path = plugin_dir_path( __FILE__ );
2197 $this->setup();
2198 }
2199 public static function get_instance() {
2200 if ( ! isset( self::$instance ) ) {
2201 self::$instance = new self();
2202 }
2203 return self::$instance;
2204 }
2205 private function setup() {
2206 add_action( 'bp_loaded', array( $this, 'load' ) );
2207 add_action( 'bp_widgets_init', array( $this, 'register_widget' ), 10 );
2208 add_action( 'bp_init', array( $this, 'load_text_domain' ) );
2209 }
2210 public function load() {
2211 require_once $this->path . 'class-bp-extended-user-groups-widget.php';
2212 }
2213 public function load_text_domain() {
2214 load_plugin_textdomain( 'bp-extended-user-groups-widget', FALSE, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
2215 }
2216 public function register_widget() {
2217 register_widget( 'BP_Extended_User_Groups_Widget' );
2218 }
2219}
2220BP_Extended_User_Groups_Widget_Helper::get_instance();
2221
2222
2223/* Change the BuddyPress Core Friends Widget Title to Say "My Friends" Instead of Using the Displayed User's Name Who's Profile We are Viewing */
2224class BP_Core_Friends_Widget extends WP_Widget {
2225 function __construct() {
2226 $widget_ops = array(
2227 'description' => __( 'A dynamic list of recently active, popular, and newest Friends of the displayed member. Widget is only shown when viewing a member profile.', 'buddypress' ),
2228 'classname' => 'widget_bp_core_friends_widget buddypress widget',
2229 'customize_selective_refresh' => true,
2230 );
2231 parent::__construct( false, $name = _x( '(BuddyPress) Friends', 'widget name', 'buddypress' ), $widget_ops );
2232 if ( is_customize_preview() || is_active_widget( false, false, $this->id_base ) ) {
2233 add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
2234 }
2235 }
2236 public function enqueue_scripts() {
2237 $min = bp_core_get_minified_asset_suffix();
2238 wp_enqueue_script( 'bp_core_widget_friends-js', buddypress()->plugin_url . "bp-friends/js/widget-friends{$min}.js", array( 'jquery' ), bp_get_version() );
2239 }
2240 function widget( $args, $instance ) {
2241 global $members_template;
2242 extract( $args );
2243 if ( ! bp_displayed_user_id() ) {
2244 return;
2245 }
2246 $user_id = bp_displayed_user_id();
2247 $link = trailingslashit( bp_displayed_user_domain() . bp_get_friends_slug() );
2248 $instance['title'] = sprintf( __( "My Friends", 'buddypress' ), bp_get_displayed_user_fullname() );
2249 if ( empty( $instance['friend_default'] ) ) {
2250 $instance['friend_default'] = 'active';
2251 }
2252 $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
2253 echo $before_widget;
2254 $title = $instance['link_title'] ? '<a href="' . esc_url( $link ) . '">' . esc_html( $title ) . '</a>' : esc_html( $title );
2255 echo $before_title . $title . $after_title;
2256 $members_args = array(
2257 'user_id' => absint( $user_id ),
2258 'type' => sanitize_text_field( $instance['friend_default'] ),
2259 'max' => absint( $instance['max_friends'] ),
2260 'populate_extras' => 1,
2261 );
2262 // Back up the global.
2263 $old_members_template = $members_template;
2264 ?>
2265 <?php if ( bp_has_members( $members_args ) ) : ?>
2266 <div class="item-options" id="friends-list-options">
2267 <a href="<?php bp_members_directory_permalink(); ?>" id="newest-friends" <?php if ( $instance['friend_default'] == 'newest' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Newest', 'buddypress' ); ?></a>
2268 | <a href="<?php bp_members_directory_permalink(); ?>" id="recently-active-friends" <?php if ( $instance['friend_default'] == 'active' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Active', 'buddypress' ); ?></a>
2269 | <a href="<?php bp_members_directory_permalink(); ?>" id="popular-friends" <?php if ( $instance['friend_default'] == 'popular' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Popular', 'buddypress' ); ?></a>
2270 </div>
2271 <ul id="friends-list" class="item-list">
2272 <?php while ( bp_members() ) : bp_the_member(); ?>
2273 <li class="vcard">
2274 <div class="item-avatar">
2275 <a href="<?php bp_member_permalink(); ?>" class="bp-tooltip" data-bp-tooltip="<?php bp_member_name(); ?>"><?php bp_member_avatar(); ?></a>
2276 </div>
2277 <div class="item">
2278 <div class="item-title fn"><a href="<?php bp_member_permalink(); ?>"><?php bp_member_name(); ?></a></div>
2279 <div class="item-meta">
2280 <?php if ( 'newest' == $instance['friend_default'] ) : ?>
2281 <span class="activity" data-livestamp="<?php bp_core_iso8601_date( bp_get_member_registered( array( 'relative' => false ) ) ); ?>"><?php bp_member_registered(); ?></span>
2282 <?php elseif ( 'active' == $instance['friend_default'] ) : ?>
2283 <span class="activity" data-livestamp="<?php bp_core_iso8601_date( bp_get_member_last_active( array( 'relative' => false ) ) ); ?>"><?php bp_member_last_active(); ?></span>
2284 <?php else : ?>
2285 <span class="activity"><?php bp_member_total_friend_count(); ?></span>
2286 <?php endif; ?>
2287 </div>
2288 </div>
2289 </li>
2290 <?php endwhile; ?>
2291 </ul>
2292 <?php wp_nonce_field( 'bp_core_widget_friends', '_wpnonce-friends' ); ?>
2293 <input type="hidden" name="friends_widget_max" id="friends_widget_max" value="<?php echo absint( $instance['max_friends'] ); ?>" />
2294 <?php else: ?>
2295 <div class="widget-error">
2296 <?php _e( 'Sorry, no members were found.', 'buddypress' ); ?>
2297 </div>
2298 <?php endif; ?>
2299 <?php echo $after_widget;
2300 // Restore the global.
2301 $members_template = $old_members_template;
2302 }
2303 function update( $new_instance, $old_instance ) {
2304 $instance = $old_instance;
2305 $instance['max_friends'] = absint( $new_instance['max_friends'] );
2306 $instance['friend_default'] = sanitize_text_field( $new_instance['friend_default'] );
2307 $instance['link_title'] = (bool) $new_instance['link_title'];
2308 return $instance;
2309 }
2310 function form( $instance ) {
2311 $defaults = array(
2312 'max_friends' => 5,
2313 'friend_default' => 'active',
2314 'link_title' => false
2315 );
2316 $instance = wp_parse_args( (array) $instance, $defaults );
2317 $max_friends = $instance['max_friends'];
2318 $friend_default = $instance['friend_default'];
2319 $link_title = (bool) $instance['link_title'];
2320 ?>
2321 <p><label for="<?php echo $this->get_field_id( 'link_title' ); ?>"><input type="checkbox" name="<?php echo $this->get_field_name('link_title'); ?>" id="<?php echo $this->get_field_id( 'link_title' ); ?>" value="1" <?php checked( $link_title ); ?> /> <?php _e( 'Link widget title to Members directory', 'buddypress' ); ?></label></p>
2322 <p><label for="<?php echo $this->get_field_id( 'max_friends' ); ?>"><?php _e( 'Max friends to show:', 'buddypress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_friends' ); ?>" name="<?php echo $this->get_field_name( 'max_friends' ); ?>" type="text" value="<?php echo absint( $max_friends ); ?>" style="width: 30%" /></label></p>
2323 <p>
2324 <label for="<?php echo $this->get_field_id( 'friend_default' ) ?>"><?php _e( 'Default friends to show:', 'buddypress' ); ?></label>
2325 <select name="<?php echo $this->get_field_name( 'friend_default' ); ?>" id="<?php echo $this->get_field_id( 'friend_default' ); ?>">
2326 <option value="newest" <?php selected( $friend_default, 'newest' ); ?>><?php _e( 'Newest', 'buddypress' ); ?></option>
2327 <option value="active" <?php selected( $friend_default, 'active' );?>><?php _e( 'Active', 'buddypress' ); ?></option>
2328 <option value="popular" <?php selected( $friend_default, 'popular' ); ?>><?php _e( 'Popular', 'buddypress' ); ?></option>
2329 </select>
2330 </p>
2331 <?php
2332 }
2333}
2334
2335
2336/* Add a "Brands I've Added to My Feed" Widget to All User's Profiles */
2337class BP_My_Followers_Widget extends WP_Widget {
2338 function __construct() {
2339 // Set up optional widget args.
2340 $widget_ops = array(
2341 'classname' => 'widget_bp_my_followers_widget widget buddypress',
2342 'description' => __( "Show a list of users that have added the displayed user or account to their feeds.", 'buddypress-followers' )
2343 );
2344 // Set up the widget.
2345 parent::__construct(
2346 false,
2347 __( "(BP Follow) My Followers Widget", 'buddypress-followers' ),
2348 $widget_ops
2349 );
2350 }
2351 //Displays the widget.
2352 function widget( $args, $instance, $member_args ) {
2353 if ( empty( $instance['max_users'] ) ) {
2354 $instance['max_users'] = 16;
2355 }
2356 // If the displayed user hasn't added any brand accounts, then hide the widget.
2357 if ( ! $following = bp_get_follower_ids( array( 'user_id' => bp_displayed_user_id() ) ) ) {
2358 return false;
2359 }
2360 // If the displayed user has added brand accounts to their feed, then show the profile photos of the brand accounts.
2361 if ( bp_has_members( array(
2362 'include' => $following,
2363 'max' => $instance['max_users'],
2364 'populate_extras' => false,
2365 'type' => 'active',
2366 ) ) ) {
2367 do_action( 'bp_before_following_widget' );
2368 echo $args['before_widget'];
2369 echo $args['before_title']
2370 . $instance['title']
2371 . $args['after_title'];
2372 ?>
2373 <div class="avatar-block">
2374 <?php while ( bp_members() ) : bp_the_member(); ?>
2375 <div class="item-avatar">
2376 <a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_avatar() ?></a>
2377 </div>
2378 <?php endwhile; ?>
2379 </div>
2380 <?php echo $args['after_widget']; ?>
2381 <?php do_action( 'bp_after_following_widget' ); ?>
2382 <?php
2383 }
2384 }
2385 //Callback to save widget settings.
2386 function update( $new_instance, $old_instance ) {
2387 $instance = $old_instance;
2388 $instance['title'] = strip_tags( $new_instance['title'] );
2389 $instance['max_users'] = (int) $new_instance['max_users'];
2390 return $instance;
2391 }
2392 //Widget settings form.
2393 function form( $instance ) {
2394 $instance = wp_parse_args( (array) $instance, array(
2395 'title' => __( "My Followers", 'buddypress-followers' ),
2396 'max_users' => 16
2397 ) );
2398 ?>
2399 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
2400 <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>
2401 <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>
2402 <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>
2403 <?php
2404 }
2405}
2406add_action( 'widgets_init', create_function( '', 'return register_widget("BP_My_Followers_Widget");' ) );
2407
2408
2409/* Change the rtMedia Widget to Allow Us to Display Our Users Photos, Videos, Etc. on Their Profile Instead of the Sitewide Media */
2410function rtm_custom_widget_add_filter_update_where_query(){
2411 if( function_exists( "bp_displayed_user_id" ) && bp_displayed_user_id () != 0 ){
2412 add_filter( "rtmedia-model-where-query", 'rtm_custom_widget_function_update_where_query', 20, 2 );
2413 }
2414}
2415function rtm_custom_widget_function_update_where_query( $where, $table_name ){
2416 $disp_user = bp_displayed_user_id();
2417 $where .= " AND ( {$table_name}.context = 'profile' and {$table_name}.context_id = '".$disp_user."' ) ";
2418 add_action( 'rtmedia_after_gallery_widget_content', 'rtm_custom_widget_remove_filter_update_where_query', 10 );
2419 return $where;
2420}
2421function rtm_custom_widget_remove_filter_update_where_query(){
2422 remove_filter( 'rtmedia-model-where-query', 'rtm_custom_widget_add_filter_update_where_query' );
2423}
2424add_action( 'rtmedia_before_gallery_widget_content','rtm_custom_widget_add_filter_update_where_query', 10 );
2425
2426
2427/* 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 */
2428function millionairesdigest_private_categories( $exclusions, $args ) {
2429 global $pagenow;
2430 if ( in_array( $pagenow,array( 'post-new.php' ) ) && !current_user_can( 'view_private_company_categories') ) {
2431 $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')";
2432 }
2433 return $exclusions;
2434}
2435add_filter('list_terms_exclusions', 'millionairesdigest_private_categories', 10, 2);
2436
2437
2438/* Hide the Featured Image on Single Custom Post Type "Videos" as the Featured Image Causes a Duplicate View of the Set Video Image */
2439function millionairesdigest_featured_image() {
2440 if( is_single() && get_post_type() == 'video' ) { ?>
2441 <style>
2442 .has-post-thumbnail img.wp-post-image {
2443 display: none;
2444 }
2445 </style>
2446 <?php
2447 }
2448}
2449add_action('wp_head', 'millionairesdigest_featured_image');
2450
2451
2452/* Create a Recent Profile Visitors Widget Since the Current BuddyPress Recent Profile Visitors Plugin That Provides the Feature Doesn't Do It */
2453function recent_profile_visitors_widget_load_widget() {
2454 register_widget( 'recent_profile_visitors_widget' );
2455}
2456add_action( 'widgets_init', 'recent_profile_visitors_widget_load_widget' );
2457
2458// Creating the widget
2459class recent_profile_visitors_widget extends WP_Widget {
2460 function __construct() {
2461 parent::__construct(
2462 // Base ID of your widget
2463 'recent_profile_visitors_widget',
2464 // Widget name will appear in UI
2465 __('BuddyPress Recent Profile Visitors', 'recent_profile_visitors_widget_domain'),
2466 // Widget description
2467 array( 'description' => __( 'Display the recent profile visitors of the current loggedin user', 'recent_profile_visitors_widget_domain' ),
2468 ) );
2469 }
2470
2471// Creating widget front-end
2472public function widget( $args, $instance ) {
2473 //Hide the widget if user has turned recording off or if the user does not have one of the following member types
2474 $user_id = bp_loggedin_user_id();
2475 if ( ! is_super_admin() && ! bp_has_member_type( $user_id, 'user' ) && ! bp_has_member_type( $user_id, 'millionaires-digest' ) )
2476 return;
2477 if ( ! visitors_is_active_visitor_recording( $user_id ) )
2478 return;
2479 $title = apply_filters( 'widget_title', $instance['title'] );
2480 // Before and after widget arguments are defined by themes
2481 echo $args['before_widget'];
2482 if ( ! empty( $title ) )
2483 echo $args['before_title'] . $title . $args['after_title'];
2484 // Run the code and display the output
2485 echo do_shortcode( '[bp-visitors-recent-visitors]', 'recent_profile_visitors_widget_domain' );
2486 echo $args['after_widget'];
2487}
2488
2489// Widget Backend
2490public function form( $instance ) {
2491 if ( isset( $instance[ 'title' ] ) ) {
2492 $title = $instance[ 'title' ];
2493 }
2494 else {
2495 $title = __( 'Recent Profile Visitors', 'recent_profile_visitors_widget_domain' );
2496 }
2497// Widget admin form
2498?>
2499<p>
2500 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
2501 <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( $title ); ?>" />
2502</p>
2503<?php
2504}
2505
2506// Updating widget replacing old instances with new
2507public function update( $new_instance, $old_instance ) {
2508 $instance = array();
2509 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
2510 return $instance;
2511 }
2512} // Class recent_profile_visitors_widget ends here
2513
2514
2515/* Register the "Recommended a Post" action from the BuddyBoss BuddyPress User Blog Plugin so It Can Be Displayed in the Backend Actiiy Stream Properly */
2516function millionairesdigest_register_recommended_post_action() {
2517 global $bp;
2518 bp_activity_set_action(
2519 $bp->activity->id,
2520 'recommended_post_activity',
2521 __( 'Recommended a post', 'buddypress' )
2522 );
2523 do_action( 'bp_activity_register_activity_actions' );
2524 // Backpat. Don't use this.
2525 do_action( 'updates_register_activity_actions' );
2526}
2527add_action( 'bp_register_activity_actions', 'millionairesdigest_register_recommended_post_action' );
2528
2529
2530/* Hide the Annoying "rtMedia Add-On Update" Admin Notice in the Backend Dashboard */
2531function millionairesdigest_hide_rtmedia_admin_notice() {
2532 echo '<style> .rtmedia_error { display: none !important; }</style>';
2533}
2534add_action( 'admin_head', 'millionairesdigest_hide_rtmedia_admin_notice');
2535
2536
2537/* Add Support for Allowing Us to Display the BuddyBoss BuddyPress User Blog Bookmark Button as a Shortcode */
2538if ( ! function_exists( 'kl_shortcode' ) ) {
2539 function kl_shortcode() {
2540 return sap_get_bookmark_button( get_the_ID(), 0 );
2541 }
2542 add_shortcode( 'bookmark', 'kl_shortcode' );
2543}
2544
2545
2546function my_nav_menu_notif_counter($menu) {
2547 $url = bp_core_get_user_domain(bp_loggedin_user_id()) .'notifications/';
2548 // condition: user must be loggedin
2549 if (!is_user_logged_in())
2550 return $menu;
2551 else
2552 $notif = '<li><a href=" ' .$url. ' ">Notifications['. bp_notifications_get_unread_notification_count( bp_loggedin_user_id() ) .']</a </li>';
2553 $menu = $menu . $notif;
2554 return $menu;
2555}
2556add_filter( 'wp_nav_menu_items', 'my_nav_menu_notif_counter' );
2557
2558
2559
2560/* 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 */
2561function get_user_role( $role_name ) {
2562 global $current_user;
2563 $user = 'User';
2564 $subscriber = 'Subscriber';
2565 $customer = 'Customer';
2566 $brand_account = 'Brand Account';
2567 $famous_person_account = 'Famous Person';
2568 $organization_account = 'Organization Account';
2569 $government_account = 'Government Account';
2570 $contributor = 'Contributor';
2571 $photographer = 'Photographer';
2572 $author = 'VIP Writer';
2573 $editor = 'Editor';
2574 $publisher = 'Publisher';
2575 $magazine_author = 'Magazine Writer';
2576 $magazine_photographer = 'Magazine Photographer';
2577 $magazine_editor = 'Magazine Editor';
2578 $magazine_designer = 'Magazine Designer';
2579 $magazine_publisher = 'Magazine Publisher';
2580 $administrator = 'Founder';
2581 if ( ! $role_name )
2582 $role_name = $current_user->ID;
2583 if ( is_user_logged_in() ) {
2584 $user_role = new WP_User( $role_name );
2585 if ( !empty( $user_role->roles ) && is_array( $user_role->roles ) ) {
2586 foreach ( $user_role->roles as $role )
2587 if ( $role == 'user' ) {
2588 return $user;
2589 } else if
2590 ( $role == 'subscriber' ) {
2591 return $subscriber;
2592 } else if
2593 ( $role == 'customer' ) {
2594 return $customer;
2595 } else if
2596 ( $role == 'brand-account' ) {
2597 return $brand_account;
2598 } else if
2599 ( $role == 'famous-person-account' ) {
2600 return $famous_person_account;
2601 } else if
2602 ( $role == 'organization-account' ) {
2603 return $organization_account;
2604 } else if
2605 ( $role == 'government-account' ) {
2606 return $government_account;
2607 } else if
2608 ( $role == 'contributor' ) {
2609 return $contributor;
2610 } else if
2611 ( $role == 'photographer' ) {
2612 return $photographer;
2613 } else if
2614 ( $role == 'author' ) {
2615 return $author;
2616 } else if
2617 ( $role == 'editor' ) {
2618 return $editor;
2619 } else if
2620 ( $role == 'publisher' ) {
2621 return $publisher;
2622 } else if
2623 ( $role == 'magazine-author' ) {
2624 return $magazine_author;
2625 } else if
2626 ( $role == 'magazine-photographer' ) {
2627 return $magazine_photographer;
2628 } else if
2629 ( $role == 'magazine-editor' ) {
2630 return $magazine_editor;
2631 } else if
2632 ( $role == 'magazine-designer' ) {
2633 return $magazine_designer;
2634 } else if
2635 ( $role == 'magazine-publisher' ) {
2636 return $magazine_publisher;
2637 } else if
2638 ( $role == 'administrator' ) {
2639 return $administrator;
2640 }
2641 return;
2642 }
2643 }
2644}
2645//Add the shortcode to display the logged-in user's role
2646if ( ! function_exists( 'kk_shortcode' ) ) {
2647 function kk_shortcode() {
2648 return get_user_role( $role_name );
2649 }
2650 add_shortcode( 'display_user_role', 'kk_shortcode' );
2651}
2652
2653
2654/* 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 */
2655function pp_private_add_meta_box() {
2656 $args = array(
2657 'public' => true,
2658 );
2659 $output = 'names';
2660 $post_types = get_post_types( $args, $output );
2661 $pp_private_cpts = array( 'post','article','video','photo','audio','page','company', array() );
2662 foreach ( $post_types as $post_type ) {
2663 if ( ! in_array( $post_type, $skip_these_bbPress ) ) {
2664 if ( in_array( $post_type, $pp_private_cpts ) ) {
2665 add_meta_box(
2666 'pp_private_sectionid',
2667 __( 'Logged-In Users Only', 'bp-simple-private' ),
2668 'pp_private_meta_box_callback',
2669 $post_type,
2670 'side',
2671 'high'
2672 );
2673 }
2674 }
2675 }
2676}
2677add_action( 'add_meta_boxes', 'pp_private_add_meta_box' );
2678// Print the box content
2679function pp_private_meta_box_callback( $post ) {
2680 $front_id = get_option('page_on_front');
2681 if ( $post->ID == $front_id )
2682 _e( 'This is your Front Page - and cannot be Private.', 'bp-simple-private' );
2683 else {
2684 wp_nonce_field( 'pp_private_save_meta_box_data', 'pp_private_meta_box_nonce' );
2685 $value = get_post_meta( $post->ID, 'pp-private', true );
2686 ?>
2687 <input type="checkbox" id="pp-private" name="pp-private" value="1" <?php checked( $value, 1 ); ?> />
2688 <label for="pp_private">
2689 <?php _e( 'Yes - This post or page is available to logged-in users only', 'bp-simple-private' ); ?>
2690 </label>
2691<?php
2692 }
2693}
2694// Save or delete meta box data when the post is saved or updated
2695function pp_private_save_meta_box_data( $post_id ) {
2696 if ( ! isset( $_POST['pp_private_meta_box_nonce'] ) )
2697 return;
2698 if ( ! wp_verify_nonce( $_POST['pp_private_meta_box_nonce'], 'pp_private_save_meta_box_data' ) )
2699 return;
2700 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
2701 return;
2702 // check user permissions
2703 if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {
2704 if ( ! current_user_can( 'manage_options', $post_id ) )
2705 return;
2706 }
2707 else {
2708 if ( ! current_user_can( 'manage_options', $post_id ) )
2709 return;
2710 }
2711 // update or delete the post_meta
2712 if ( ! isset( $_POST['pp-private'] ) )
2713 delete_post_meta($post_id, 'pp-private', '');
2714 else {
2715 $front_id = get_option('page_on_front');
2716 if ( $post_id != $front_id ) {
2717 $private_data = sanitize_text_field( $_POST['pp-private'] );
2718 update_post_meta( $post_id, 'pp-private', $private_data );
2719 }
2720 else
2721 delete_post_meta($post_id, 'pp-private', '');
2722 }
2723}
2724add_action( 'save_post', 'pp_private_save_meta_box_data' );
2725//Add the metabox
2726function pp_private_check() {
2727 global $wp;
2728 if ( ! is_admin() && ! is_user_logged_in() ) {
2729 if ( is_front_page() || is_home() || bp_is_register_page() || bp_is_activation_page() )
2730 return;
2731 $redirect_url = trailingslashit( site_url() );
2732 $pp_private_components = get_option( 'pp-private-components' );
2733 if ( $pp_private_components == false )
2734 $pp_private_components = array();
2735 if ( bp_is_user() && in_array( 'member Profile Pages', $pp_private_components ) )
2736 bp_core_redirect( $redirect_url );
2737 $bp_current_component = bp_current_component();
2738 if ( false != $bp_current_component ) {
2739 if ( in_array( $bp_current_component, $pp_private_components ) )
2740 bp_core_redirect( $redirect_url );
2741 }
2742 if ( is_single() || is_page() ) {
2743 $pp_private_cpts = get_option( 'pp-private-cpts' );
2744 if ( $pp_private_cpts == false )
2745 $pp_private_cpts = array();
2746 $post_type = get_post_type( get_the_ID() );
2747 if ( in_array( $post_type, $pp_private_cpts ) ) {
2748 $pp_private = get_post_meta( get_the_ID(), 'pp-private', true );
2749 if ( $pp_private == '1' )
2750 bp_core_redirect( $redirect_url );
2751 }
2752 }
2753 }
2754}
2755add_action( 'bp_ready', 'pp_private_check' );
2756
2757
2758/* 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 */
2759function millionairesdigest_footer() {
2760 if( is_user_logged_in() ) { ?>
2761 <style>
2762 .footer-color#footer {
2763 display: none;
2764 }
2765 .socket-color {
2766 background-color: #ffffff !important;
2767 color: #777777 !important;
2768 }
2769 }
2770 </style>
2771 <?php
2772 }
2773}
2774add_action('wp_head', 'millionairesdigest_footer');
2775
2776
2777/* Remove the Following Admin Dashboad Widgets to Prevent Them from Showing Up on the Backend Dashboard Main Page */
2778function remove_admin_dashboard_widgets() {
2779 global $wp_meta_boxes;
2780 unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
2781 unset($wp_meta_boxes['dashboard']['normal']['core']['ctdl']);
2782 unset($wp_meta_boxes['dashboard']['normal']['core']['arve_dashboard_widget']);
2783 unset($wp_meta_boxes['dashboard']['normal']['core']['pmpro_db_widget']);
2784 unset($wp_meta_boxes['dashboard']['normal']['core']['rtmedia_dashboard_widget']);
2785}
2786add_action('wp_dashboard_setup', 'remove_admin_dashboard_widgets', 999);
2787
2788
2789add_filter( 'bp_core_enable_root_profiles', '__return_true' );
2790
2791
2792
2793function millionairesdigest_notifications() {
2794 if( is_user_logged_in() ) { ?>
2795 <style>
2796 .kleo-toggle-notifications-submenu, .kleo-toggle-messages-submenu {
2797 display: none !important;
2798 }
2799 }
2800 </style>
2801 <?php
2802 }
2803}
2804add_action('wp_head', 'millionairesdigest_notifications');
2805
2806
2807function mark_as_read() {
2808 if ( ! $this->is_bp_active() || ! is_singular() ) {
2809 return ;
2810 }
2811 $post_id = get_queried_object_id();
2812 if ( ! $post_id ) {
2813 return ;
2814 }
2815 return BP_Notifications_Notification::update(
2816 array( 'is_new' => 0 ),
2817 array( 'secondary_item_id' => $post_id,
2818 'component_name' => $this->id,
2819 'user_id' => get_current_user_id(),
2820 )
2821 );
2822 }
2823add_action( 'template_redirect', array( $this, 'mark_as_read' ) );
2824
2825
2826
2827/* 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 */
2828function millionairesdigest_get_send_private_message_to_user_url( $user_id ) {
2829 return wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r=' . bp_core_get_username( $user_id ) );
2830}
2831function millionairesdigest_private_message_button_shortcode( $atts, $content = '' ) {
2832 if ( ! is_user_logged_in() ) {
2833 return '';
2834 }
2835 $atts = shortcode_atts( array(
2836 'user_id' => '',
2837 'username' => '',
2838 'label' => 'Message CEO',
2839 ), $atts );
2840 $user_id = absint( $atts['user_id'] );
2841 $user_login = $atts['username'];
2842 // If the username is given, override the user id.
2843 if ( $user_login ) {
2844 $user = get_user_by( 'login', $user_login );
2845 if ( ! $user ) {
2846 return '';
2847 }
2848 $user_id = $user->ID;
2849 }
2850 if ( ! $user_id ) {
2851 if ( ! in_the_loop() ) {
2852 return '';
2853 }
2854 $user_id = get_the_author_meta('ID' );
2855 }
2856 // If we are here, generate the button.
2857 $button = sprintf('<a href="%1$s">%2$s</a>', millionairesdigest_get_send_private_message_to_user_url( $user_id ), $atts['label'] );
2858 return $button . $content;
2859}
2860add_shortcode( 'bp-pm-button', 'millionairesdigest_private_message_button_shortcode' );
2861
2862
2863
2864
2865class Kleo_Sticky_Posts_widget extends WP_Widget {
2866 /* Widget setup */
2867 function __construct() {
2868 $widget_ops = array(
2869 'description' => __( 'Display the sticky posts of an author.', 'kleo_framework' )
2870 );
2871 parent::__construct( 'kleo_sticky_posts', __('Author Sticky Posts','kleo_framework'), $widget_ops );
2872 }
2873
2874 /* Display the widget */
2875 function widget( $args, $instance ) {
2876 extract( $args, EXTR_SKIP );
2877
2878 $title = apply_filters( 'widget_title', $instance['title'] );
2879 $limit = $instance['limit'];
2880 $length = (int)( $instance['length'] );
2881 $thumb = isset($instance['thumb']) ? $instance['thumb'] : '';
2882 $excerpt = isset($instance['excerpt']) ? $instance['excerpt'] : '' ;
2883 $cat = $instance['cat'];
2884 $post_type = $instance['post_type'];
2885
2886 global $authordata, $post;
2887 $args = array(
2888 'numberposts' => $limit,
2889 'cat' => $cat,
2890 'post_type' => $post_type,
2891 'suppress_filters' => false
2892 );
2893
2894 $kleo_recent_posts = get_posts( array(
2895 'author' => $authordata->ID,
2896 'numberposts' => $limit,
2897 'cat' => $cat,
2898 'post_type' => $post_type,
2899 'suppress_filters' => false
2900 ) );
2901
2902 if ( ! empty( $kleo_recent_posts ) ) {
2903 echo $before_widget;
2904 if ( ! empty( $title ) ) {
2905 echo $before_title . $title . $after_title;
2906 }
2907 ?>
2908 <div>
2909 <ul class='news-widget-wrap'>
2910 <?php foreach ( $kleo_recent_posts as $post ) : setup_postdata( $post ); ?>
2911 <li class="news-content">
2912 <a class="news-link" href="<?php the_permalink(); ?>">
2913 <?php if ( $thumb == 1 ) : /* Display author image */ ?>
2914 <span class="news-thumb"><?php echo get_avatar( get_the_author_meta( 'ID' ), 40 ); ?></span>
2915 <span class="news-headline"><?php the_title(); ?>
2916 <small class="news-time"><?php echo get_the_date(); ?></small></span>
2917 <?php if ( $excerpt == 1 ) { ?>
2918 <span class="news-excerpt"><?php echo kleo_excerpt( $length, false ); ?></span>
2919 <?php } ?>
2920 <?php elseif ( $thumb == 2 ) : /* Display post thumbnail */ ?>
2921 <?php
2922 $img_url = kleo_get_post_thumbnail_url();
2923 if ( $img_url != '' ) {
2924 $image = aq_resize( $img_url, 44, 44, true, true, true );
2925 if ( ! $image ) {
2926 $image = $img_url;
2927 }
2928 $html_img = '<img src="' . $image . '" alt="" title="">';
2929 } else {
2930 $html_img = '';
2931 }
2932 ?>
2933 <span class="news-thumb"><?php echo $html_img; ?></span>
2934 <span class="news-headline"><?php the_title(); ?>
2935 <small class="news-time"><?php echo get_the_date(); ?></small></span>
2936 <?php if ( $excerpt == 1 ) { ?>
2937 <span class="news-excerpt"><?php echo kleo_excerpt( $length, false ); ?></span>
2938 <?php } ?>
2939 <?php else : ?>
2940 <span><?php the_title(); ?>
2941 <small class="news-time"><?php echo get_the_date(); ?></small></span>
2942 <?php if ( $excerpt == 1 ) { ?>
2943 <span class="news-excerpt"><?php echo kleo_excerpt( $length, false ); ?></span>
2944 <?php } ?>
2945 <?php endif; ?>
2946 </a>
2947 </li>
2948 <?php endforeach;
2949 wp_reset_postdata(); ?>
2950 </ul>
2951 </div>
2952 <?php
2953 echo $after_widget;
2954 }
2955 }
2956
2957 /* Update widget */
2958 function update( $new_instance, $old_instance ) {
2959 $instance = $old_instance;
2960 $instance['title'] = esc_attr( $new_instance['title'] );
2961 $instance['limit'] = $new_instance['limit'];
2962 $instance['length'] = (int)( $new_instance['length'] );
2963 $instance['thumb'] = $new_instance['thumb'];
2964 $instance['excerpt'] = $new_instance['excerpt'];
2965 $instance['cat'] = $new_instance['cat'];
2966 $instance['post_type'] = $new_instance['post_type'];
2967 return $instance;
2968 }
2969
2970 /* Widget setting */
2971 function form( $instance ) {
2972 $defaults = array(
2973 'title' => '',
2974 'limit' => 5,
2975 'length' => 100,
2976 'thumb' => true,
2977 'excerpt' => '',
2978 'cat' => '',
2979 'post_type' => '',
2980 'date' => true,
2981 );
2982 $instance = wp_parse_args( (array) $instance, $defaults );
2983 $title = esc_attr( $instance['title'] );
2984 $limit = $instance['limit'];
2985 $length = (int)($instance['length']);
2986 $thumb = $instance['thumb'];
2987 $excerpt = $instance['excerpt'];
2988 $cat = $instance['cat'];
2989 $post_type = $instance['post_type'];
2990 ?>
2991 <p>
2992 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:', 'kleo_framework' ); ?></label>
2993 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo $title; ?>" />
2994 </p>
2995 <p>
2996 <label for="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>"><?php _e( 'Limit:', 'kleo_framework' ); ?></label>
2997 <select class="widefat" name="<?php echo $this->get_field_name( 'limit' ); ?>" id="<?php echo $this->get_field_id( 'limit' ); ?>">
2998 <?php for ( $i=1; $i<=20; $i++ ) { ?>
2999 <option <?php selected( $limit, $i ) ?> value="<?php echo $i; ?>"><?php echo $i; ?></option>
3000 <?php } ?>
3001 </select>
3002 </p>
3003 <p>
3004 <label for="<?php echo esc_attr( $this->get_field_id( 'excerpt' ) ); ?>"><?php _e( 'Display excerpt?', 'kleo_framework' ); ?></label>
3005 <select id="<?php echo $this->get_field_id( 'excerpt' ); ?>" name="<?php echo $this->get_field_name( 'excerpt' ); ?>">
3006 <option value="">No</option>
3007 <option <?php selected( '1', $excerpt ); ?> value="1">Yes</option>
3008 </select>
3009 </p>
3010 <p>
3011 <label for="<?php echo esc_attr( $this->get_field_id( 'length' ) ); ?>"><?php _e( 'Excerpt length(characters):', 'kleo_framework' ); ?></label>
3012 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'length' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'length' ) ); ?>" type="text" value="<?php echo $length; ?>" />
3013 </p>
3014
3015 <p>
3016 <label for="<?php echo esc_attr( $this->get_field_id( 'thumb' ) ); ?>"><?php _e( 'Display Thumbnail?', 'kleo_framework' ); ?></label>
3017 <select id="<?php echo $this->get_field_id( 'thumb' ); ?>" name="<?php echo $this->get_field_name( 'thumb' ); ?>">
3018 <option value="">No</option>
3019 <option <?php selected( '1', $thumb ); ?> value="1">Author Image</option>
3020 <option <?php selected( '2', $thumb ); ?> value="2">Featured Image</option>
3021 </select>
3022 </p>
3023 <p>
3024 <label for="<?php echo esc_attr( $this->get_field_id( 'cat' ) ); ?>"><?php _e( 'Show from category: ' , 'kleo_framework' ); ?></label>
3025 <?php wp_dropdown_categories( array( 'name' => $this->get_field_name( 'cat' ), 'show_option_all' => __( 'All categories' , 'kleo_framework' ), 'hide_empty' => 1, 'hierarchical' => 1, 'selected' => $cat ) ); ?>
3026 </p>
3027 <p>
3028 <label for="<?php echo esc_attr( $this->get_field_id( 'post_type' ) ); ?>"><?php _e( 'Choose the Post Type: ' , 'kleo_framework' ); ?></label>
3029 <select class="widefat" id="<?php echo $this->get_field_id( 'post_type' ); ?>" name="<?php echo $this->get_field_name( 'post_type' ); ?>">
3030 <?php foreach ( get_post_types( '', 'objects' ) as $post_type ) { ?>
3031 <option value="<?php echo esc_attr( $post_type->name ); ?>" <?php selected( $instance['post_type'], $post_type->name ); ?>><?php echo esc_html( $post_type->labels->singular_name ); ?></option>
3032 <?php } ?>
3033 </select>
3034 </p>
3035 <?php
3036 }
3037}
3038/* Register the widget */
3039add_action( 'widgets_init', create_function( '', 'register_widget( "Kleo_Sticky_Posts_widget" );' ) );
3040
3041
3042/* Add an "Author Recent Articles" Widget for the Purpose of Allowing Us to Display More Articles Written by the Author Who's Article a User is Reading if On a Singlular Article */
3043class AuthorRecentArticles extends WP_Widget {
3044 //Constructor
3045 function AuthorRecentArticles() {
3046 parent::__construct(
3047 'author_recent_articles', // Base ID
3048 'Author Recent Articles', // Name
3049 array( 'description' => __( 'Display a list of more articles written by the same author if on a singlular article', 'text_domain' ) )
3050 );
3051 }
3052
3053 //Widget Form
3054 function form( $instance ) {
3055 $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
3056 $numberofposts = isset( $instance['numberofposts'] ) ? absint( $instance['numberofposts'] ) : 5;
3057 $show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false;
3058 $showthumbnail = isset( $instance['showthumbnail'] ) ? (bool) $instance['showthumbnail'] : false;
3059 $width = isset( $instance['width'] ) ? esc_attr($instance['width'] ) : '';
3060 $height = isset( $instance['height'] ) ? esc_attr( $instance['height'] ) : '';
3061 ?>
3062 <p>
3063 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'wp_widget_plugin' ); ?></label>
3064 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
3065 </p>
3066 <p>
3067 <label for="<?php echo $this->get_field_id( 'numberofposts' ); ?>"><?php _e( 'Number of articles to show:', 'wp_widget_plugin' ); ?></label>
3068 <input id="<?php echo $this->get_field_id( 'numberofposts' ); ?>" name="<?php echo $this->get_field_name( 'numberofposts' ); ?>" type="text" size="3" value="<?php echo $numberofposts; ?>" />
3069 </p>
3070 <p>
3071 <input class="checkbox showthumbnail" id="<?php echo $this->get_field_id( 'showthumbnail' ); ?>" name="<?php echo $this->get_field_name( 'showthumbnail' ); ?>" type="checkbox" <?php checked( $showthumbnail ); ?> /><label for="<?php echo $this->get_field_id( 'showthumbnail' ); ?>"><?php _e( 'Show Thumbnail?', 'wp_widget_plugin' ); ?></label>
3072 </p>
3073 <div class="thumbnailAttr">
3074 <p>
3075 <label for="<?php echo $this->get_field_id( 'width' ); ?>"><?php _e( 'Width: ' ); ?></label>
3076 <input size="3" id="<?php echo $this->get_field_id( 'width' ); ?>" name="<?php echo $this->get_field_name( 'width' ); ?>" type="text" value="<?php echo $width; ?>" /> px
3077 </p>
3078 <p>
3079 <label for="<?php echo $this->get_field_id( 'height' ); ?>"><?php _e( 'Height: ' ); ?></label>
3080 <input size="3" id="<?php echo $this->get_field_id( 'height' ); ?>" name="<?php echo $this->get_field_name( 'height' ); ?>" type="text" value="<?php echo $height; ?>" /> px
3081 </p>
3082 </div>
3083 <p><input class="checkbox" type="checkbox" <?php checked( $show_date ); ?> id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" />
3084 <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Display article date?' ); ?></label></p>
3085 <?php
3086 }
3087
3088 //Widget Update
3089 function update( $new_instance, $old_instance ) {
3090 $old_instance['title'] = $new_instance['title'];
3091 $old_instance['numberofposts'] = isset( $new_instance['numberofposts'] )? (int)$new_instance['numberofposts']:'';
3092 $old_instance['showthumbnail'] = isset( $new_instance['showthumbnail'] ) ? (bool) $new_instance['showthumbnail'] : false;
3093 $old_instance['width'] = isset( $new_instance['width'] ) ? $new_instance['width']:'';
3094 $old_instance['height'] = isset( $new_instance['height'] ) ? $new_instance['height']:'';
3095 $old_instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false;
3096 return $old_instance;
3097 }
3098
3099 //Widget Display
3100 function widget( $args, $instance ) {
3101 extract( $args );
3102 $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Author Recent Articles' );
3103 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
3104 $number = ( ! empty( $instance['numberofposts'] ) ) ? absint( $instance['numberofposts'] ) : 5;
3105 $showthumbnail = isset( $instance['showthumbnail'] ) ? $instance['showthumbnail'] : false;
3106 $width_image = empty( $instance['width'] ) ? '50' : apply_filters( 'widget_image_width', $instance['width'] );
3107 $height_image = empty( $instance['height'] ) ? '50' : apply_filters('widget_image_height', $instance['height']);
3108 $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
3109
3110 if ( is_single() ) {
3111 global $authordata, $post;
3112 $authors_posts = get_posts( array(
3113 'author' => $authordata->ID,
3114 'post_type' => 'article',
3115 'post__not_in' => array( $post->ID ),
3116 'posts_per_page' => $number
3117 ) );
3118 if ( count( $authors_posts ) > 0 ) :
3119 ?>
3120 <?php echo $before_widget; ?>
3121 <?php if ( $title )
3122 {
3123 $author = get_the_author_meta( 'display_name', $authordata->ID );
3124 $title = str_replace( '[author]', $author, $title );
3125 echo $before_title . $title . $after_title;
3126 }
3127 ?>
3128 <ul class="author_article">
3129 <?php foreach ( $authors_posts as $authors_post ) { ?>
3130 <li>
3131 <?php if( $showthumbnail ) : ?>
3132 <div class="author_left" style="width:<?php echo $width_image; ?>px;height:<?php echo $height_image; ?>px;">
3133 <?php
3134 if( $showthumbnail ) {
3135 if( has_post_thumbnail( $authors_post->ID ) ) {
3136 ?>
3137 <a href="<?php echo get_permalink( $authors_post->ID ); ?>">
3138 <?php
3139 echo get_the_post_thumbnail( $authors_post->ID, array( $width_image,$height_image ) ); ?>
3140 </a>
3141 <?php }
3142 else {
3143 ?>
3144 <a href="<?php echo get_permalink( $authors_post->ID ); ?>">
3145 <?php
3146 echo get_avatar( get_the_author_meta( 'ID' ), 40 ); ?>
3147 </a>
3148 <?php
3149 }
3150 }
3151 ?>
3152 </div>
3153 <?php endif; ?>
3154 <div class="author_right">
3155 <a href="<?php echo get_permalink( $authors_post->ID ) ; ?>">
3156 <?php
3157 echo apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ); ?>
3158 </a>
3159 <?php if ( $show_date ) : ?>
3160 <br /><span class="post-date"><small><?php echo date( get_option( 'date_format' ), strtotime( $authors_post->post_date ) ); ?></small></span>
3161 <?php endif; ?>
3162 </div>
3163 </li>
3164 <?php } ?>
3165 </ul>
3166 <?php echo $after_widget; ?>
3167<?php
3168 // Reset the global $the_post as this query will have stomped on it
3169 wp_reset_postdata();
3170 endif ;
3171 } // single page condition ends here
3172 }// widget function end here
3173 } // class end tag
3174// register widget
3175add_action( 'widgets_init', create_function( '', 'return register_widget( "AuthorRecentArticles" );' ) );
3176
3177
3178/* Add an "Author Recent Videos" Widget for the Purpose of Allowing Us to Display More Videos Created by the Author Who's Video a User is Watching if On a Singlular Video */
3179class AuthorRecentVideos extends WP_Widget {
3180 //Constructor
3181 function AuthorRecentVideos() {
3182 parent::__construct(
3183 'author_recent_videos', // Base ID
3184 'Author Recent Videos', // Name
3185 array( 'description' => __( 'Display a list of more videos created by the same author if on a singlular video', 'text_domain' ) )
3186 );
3187 }
3188
3189 //Widget Form
3190 function form( $instance ) {
3191 $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
3192 $numberofposts = isset( $instance['numberofposts'] ) ? absint( $instance['numberofposts'] ) : 5;
3193 $show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false;
3194 $showthumbnail = isset( $instance['showthumbnail'] ) ? (bool) $instance['showthumbnail'] : false;
3195 $width = isset( $instance['width'] ) ? esc_attr( $instance['width'] ) : '';
3196 $height = isset( $instance['height'] ) ? esc_attr( $instance['height']) : '';
3197 $alternateImg = isset( $instance['alternateImg'] ) ? esc_attr( $instance['alternateImg'] ) : '';
3198 ?>
3199 <p>
3200 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'wp_widget_plugin' ); ?></label>
3201 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
3202 </p>
3203 <p>
3204 <label for="<?php echo $this->get_field_id( 'numberofposts' ); ?>"><?php _e( 'Number of videos to show:', 'wp_widget_plugin' ); ?></label>
3205 <input id="<?php echo $this->get_field_id( 'numberofposts' ); ?>" name="<?php echo $this->get_field_name( 'numberofposts' ); ?>" type="text" size="3" value="<?php echo $numberofposts; ?>" />
3206 </p>
3207 <p>
3208 <input class="checkbox showthumbnail" id="<?php echo $this->get_field_id( 'showthumbnail' ); ?>" name="<?php echo $this->get_field_name( 'showthumbnail' ); ?>" type="checkbox" <?php checked( $showthumbnail ); ?> /><label for="<?php echo $this->get_field_id( 'showthumbnail' ); ?>"><?php _e( 'Show Thumbnail?', 'wp_widget_plugin' ); ?></label>
3209 </p>
3210 <div class="thumbnailAttr">
3211 <p>
3212 <label for="<?php echo $this->get_field_id( 'width' ); ?>"><?php _e( 'Width: ' ); ?></label>
3213 <input size="3" id="<?php echo $this->get_field_id( 'width' ); ?>" name="<?php echo $this->get_field_name( 'width' ); ?>" type="text" value="<?php echo $width; ?>" /> px
3214 </p>
3215 <p>
3216 <label for="<?php echo $this->get_field_id( 'height' ); ?>"><?php _e( 'Height: ' ); ?></label>
3217 <input size="3" id="<?php echo $this->get_field_id( 'height' ); ?>" name="<?php echo $this->get_field_name( 'height' ); ?>" type="text" value="<?php echo $height; ?>" /> px
3218 </p>
3219 <p>
3220 <label for="<?php echo $this->get_field_id( 'alternateImg' ); ?>"><?php _e( 'Alternate image url:', 'wp_widget_plugin' ); ?></label>
3221 <input class="widefat" id="<?php echo $this->get_field_id( 'alternateImg' ); ?>" name="<?php echo $this->get_field_name( 'alternateImg' ); ?>" type="text" value="<?php echo $alternateImg; ?>" />
3222 </p>
3223 </div>
3224 <p><input class="checkbox" type="checkbox" <?php checked( $show_date ); ?> id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" />
3225 <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Display video date?' ); ?></label></p>
3226 <?php
3227 }
3228
3229 //Widget Update
3230 function update( $new_instance, $old_instance ) {
3231 $old_instance['title'] = $new_instance['title'];
3232 $old_instance['numberofposts'] = isset( $new_instance['numberofposts'] ) ? (int)$new_instance['numberofposts']:'';
3233 $old_instance['showthumbnail'] = isset( $new_instance['showthumbnail'] ) ? (bool) $new_instance['showthumbnail'] : false;
3234 $old_instance['width'] = isset( $new_instance['width'] ) ? $new_instance['width']:'';
3235 $old_instance['height'] = isset( $new_instance['height'] ) ? $new_instance['height']:'';
3236 $old_instance['alternateImg'] = isset( $new_instance['alternateImg'] ) ? $new_instance['alternateImg']:'';
3237 $old_instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false;
3238 return $old_instance;
3239 }
3240
3241 //Widget Display
3242 function widget( $args, $instance ) {
3243 extract( $args );
3244 $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Author Recent Videos' );
3245 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
3246 $number = ( ! empty( $instance['numberofposts'] ) ) ? absint( $instance['numberofposts'] ) : 5;
3247 $showthumbnail = isset( $instance['showthumbnail'] ) ? $instance['showthumbnail'] : false;
3248 $width_image = empty( $instance['width'] ) ? '50' : apply_filters( 'widget_image_width', $instance['width'] );
3249 $height_image = empty( $instance['height'] ) ? '50' : apply_filters( 'widget_image_height', $instance['height'] );
3250 $alternateImg = !empty( $instance['alternateImg'] ) ? $instance['alternateImg']:'';
3251 $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
3252
3253 if ( is_single() ) {
3254 global $authordata, $post;
3255 $authors_posts = get_posts( array(
3256 'author' => $authordata->ID,
3257 'post_type' => 'video',
3258 'post__not_in' => array( $post->ID ),
3259 'posts_per_page' => $number
3260 ) );
3261 if ( count( $authors_posts ) > 0 ) :
3262 ?>
3263 <?php echo $before_widget; ?>
3264 <?php if ( $title )
3265 {
3266 $author = get_the_author_meta( 'display_name', $authordata->ID );
3267 $title = str_replace( '[author]', $author, $title );
3268 echo $before_title . $title . $after_title;
3269 }
3270 ?>
3271 <ul class="author_video">
3272 <?php foreach ( $authors_posts as $authors_post ) { ?>
3273 <li>
3274 <?php if( $showthumbnail ) : ?>
3275 <div class="author_left" style="width:<?php echo $width_image; ?>px;height:<?php echo $height_image; ?>px;">
3276 <?php
3277 if( $showthumbnail ) {
3278 if( has_post_thumbnail( $authors_post->ID ) ) {
3279 ?>
3280 <a href="<?php echo get_permalink( $authors_post->ID ) ; ?>">
3281 <?php
3282 echo get_the_post_thumbnail( $authors_post->ID, array( $width_image, $height_image ) ); ?>
3283 </a>
3284 <?php
3285 }
3286 elseif( $alternateImg != '') {?>
3287 <a href="<?php echo get_permalink( $authors_post->ID ) ; ?>">
3288 <img src="<?php echo $alternateImg; ?>" width="<?php echo $width_image; ?>" height="<?php echo $height_image; ?>" class="wp-video-image" />
3289 </a>
3290 <?php }
3291 }?>
3292 </div>
3293 <?php endif; ?>
3294 <div class="author_right">
3295 <a href="<?php echo get_permalink( $authors_post->ID ) ; ?>">
3296 <?php
3297 echo apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ); ?>
3298 </a>
3299 <?php if ( $show_date ) : ?>
3300 <br /><span class="post-date"><small><?php echo date( get_option( 'date_format' ), strtotime( $authors_post->post_date ) ); ?></small></span>
3301 <?php endif; ?>
3302 </div>
3303 </li>
3304 <?php } ?>
3305 </ul>
3306 <?php echo $after_widget; ?>
3307<?php
3308 // Reset the global $the_post as this query will have stomped on it
3309 wp_reset_postdata();
3310 endif;
3311 } // single page condition ends here
3312 }// widget function end here
3313 } // class end tag
3314// register widget
3315add_action( 'widgets_init', create_function( '', 'return register_widget( "AuthorRecentVideos" );' ) );
3316
3317
3318/* Add an "Author Recent Photos" Widget for the Purpose of Allowing Us to Display More Photos Taken by the Author Who's Photo a User is Viewing if On a Singlular Photo */
3319class AuthorRecentPhotos extends WP_Widget {
3320 //Constructor
3321 function AuthorRecentPhotos() {
3322 parent::__construct(
3323 'author_recent_photos', // Base ID
3324 'Author Recent Photos', // Name
3325 array( 'description' => __( 'Display a list of more photos taken by the same author if on a singlular photo', 'text_domain' ) )
3326 );
3327 }
3328
3329 //Widget Form
3330 function form( $instance ) {
3331 $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
3332 $numberofposts = isset( $instance['numberofposts'] ) ? absint( $instance['numberofposts'] ) : 5;
3333 $show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false;
3334 $showthumbnail = isset( $instance['showthumbnail'] ) ? (bool) $instance['showthumbnail'] : false;
3335 $width = isset( $instance['width'] ) ? esc_attr( $instance['width'] ) : '';
3336 $height = isset( $instance['height'] ) ? esc_attr( $instance['height']) : '';
3337 $alternateImg = isset( $instance['alternateImg'] ) ? esc_attr( $instance['alternateImg'] ) : '';
3338 ?>
3339 <p>
3340 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'wp_widget_plugin' ); ?></label>
3341 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
3342 </p>
3343 <p>
3344 <label for="<?php echo $this->get_field_id( 'numberofposts' ); ?>"><?php _e( 'Number of photos to show:', 'wp_widget_plugin' ); ?></label>
3345 <input id="<?php echo $this->get_field_id( 'numberofposts' ); ?>" name="<?php echo $this->get_field_name( 'numberofposts' ); ?>" type="text" size="3" value="<?php echo $numberofposts; ?>" />
3346 </p>
3347 <p>
3348 <input class="checkbox showthumbnail" id="<?php echo $this->get_field_id( 'showthumbnail' ); ?>" name="<?php echo $this->get_field_name( 'showthumbnail' ); ?>" type="checkbox" <?php checked( $showthumbnail ); ?> /><label for="<?php echo $this->get_field_id( 'showthumbnail' ); ?>"><?php _e( 'Show Thumbnail?', 'wp_widget_plugin' ); ?></label>
3349 </p>
3350 <div class="thumbnailAttr">
3351 <p>
3352 <label for="<?php echo $this->get_field_id( 'width' ); ?>"><?php _e( 'Width: ' ); ?></label>
3353 <input size="3" id="<?php echo $this->get_field_id( 'width' ); ?>" name="<?php echo $this->get_field_name( 'width' ); ?>" type="text" value="<?php echo $width; ?>" /> px
3354 </p>
3355 <p>
3356 <label for="<?php echo $this->get_field_id( 'height' ); ?>"><?php _e( 'Height: ' ); ?></label>
3357 <input size="3" id="<?php echo $this->get_field_id( 'height' ); ?>" name="<?php echo $this->get_field_name( 'height' ); ?>" type="text" value="<?php echo $height; ?>" /> px
3358 </p>
3359 <p>
3360 <label for="<?php echo $this->get_field_id( 'alternateImg' ); ?>"><?php _e( 'Alternate image url:', 'wp_widget_plugin' ); ?></label>
3361 <input class="widefat" id="<?php echo $this->get_field_id( 'alternateImg' ); ?>" name="<?php echo $this->get_field_name( 'alternateImg' ); ?>" type="text" value="<?php echo $alternateImg; ?>" />
3362 </p>
3363 </div>
3364 <p><input class="checkbox" type="checkbox" <?php checked( $show_date ); ?> id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" />
3365 <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Display photo date?' ); ?></label></p>
3366 <?php
3367 }
3368
3369 //Widget Update
3370 function update( $new_instance, $old_instance ) {
3371 $old_instance['title'] = $new_instance['title'];
3372 $old_instance['numberofposts'] = isset( $new_instance['numberofposts'] ) ? (int)$new_instance['numberofposts']:'';
3373 $old_instance['showthumbnail'] = isset( $new_instance['showthumbnail'] ) ? (bool) $new_instance['showthumbnail'] : false;
3374 $old_instance['width'] = isset( $new_instance['width'] ) ? $new_instance['width']:'';
3375 $old_instance['height'] = isset( $new_instance['height'] ) ? $new_instance['height']:'';
3376 $old_instance['alternateImg'] = isset( $new_instance['alternateImg'] ) ? $new_instance['alternateImg']:'';
3377 $old_instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false;
3378 return $old_instance;
3379 }
3380
3381 //Widget Display
3382 function widget( $args, $instance ) {
3383 extract( $args );
3384 $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Author Recent Photos' );
3385 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
3386 $number = ( ! empty( $instance['numberofposts'] ) ) ? absint( $instance['numberofposts'] ) : 5;
3387 $showthumbnail = isset( $instance['showthumbnail'] ) ? $instance['showthumbnail'] : false;
3388 $width_image = empty( $instance['width'] ) ? '50' : apply_filters( 'widget_image_width', $instance['width'] );
3389 $height_image = empty( $instance['height'] ) ? '50' : apply_filters( 'widget_image_height', $instance['height'] );
3390 $alternateImg = !empty( $instance['alternateImg'] ) ? $instance['alternateImg']:'';
3391 $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
3392
3393 if ( is_single() ) {
3394 global $authordata, $post;
3395 $authors_posts = get_posts( array(
3396 'author' => $authordata->ID,
3397 'post_type' => 'photo',
3398 'post__not_in' => array( $post->ID ),
3399 'posts_per_page' => $number
3400 ) );
3401 if ( count( $authors_posts ) > 0 ) :
3402 ?>
3403 <?php echo $before_widget; ?>
3404 <?php if ( $title )
3405 {
3406 $author = get_the_author_meta( 'display_name', $authordata->ID );
3407 $title = str_replace( '[author]', $author, $title );
3408 echo $before_title . $title . $after_title;
3409 }
3410 ?>
3411 <ul class="author_photo">
3412 <?php foreach ( $authors_posts as $authors_post ) { ?>
3413 <li>
3414 <?php if( $showthumbnail ) : ?>
3415 <div class="author_left" style="width:<?php echo $width_image; ?>px;height:<?php echo $height_image; ?>px;">
3416 <?php
3417 if( $showthumbnail ) {
3418 if( has_post_thumbnail( $authors_post->ID ) ) {
3419 ?>
3420 <a href="<?php echo get_permalink( $authors_post->ID ) ; ?>">
3421 <?php
3422 echo get_the_post_thumbnail( $authors_post->ID, array( $width_image, $height_image ) ); ?>
3423 </a>
3424 <?php
3425 }
3426 elseif( $alternateImg != '') {?>
3427 <a href="<?php echo get_permalink( $authors_post->ID ) ; ?>">
3428 <img src="<?php echo $alternateImg; ?>" width="<?php echo $width_image; ?>" height="<?php echo $height_image; ?>" class="wp-photo-image" />
3429 </a>
3430 <?php }
3431 }?>
3432 </div>
3433 <?php endif; ?>
3434 <div class="author_right">
3435 <a href="<?php echo get_permalink( $authors_post->ID ) ; ?>">
3436 <?php
3437 echo apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ); ?>
3438 </a>
3439 <?php if ( $show_date ) : ?>
3440 <br /><span class="post-date"><small><?php echo date( get_option( 'date_format' ), strtotime( $authors_post->post_date ) ); ?></small></span>
3441 <?php endif; ?>
3442 </div>
3443 </li>
3444 <?php } ?>
3445 </ul>
3446 <?php echo $after_widget; ?>
3447<?php
3448 // Reset the global $the_post as this query will have stomped on it
3449 wp_reset_postdata();
3450 endif;
3451 } // single page condition ends here
3452 }// widget function end here
3453 } // class end tag
3454// register widget
3455add_action( 'widgets_init', create_function( '', 'return register_widget( "AuthorRecentPhotos" );' ) );
3456
3457
3458/* Add an "Author Recent Music" Widget for the Purpose of Allowing Us to Display More Songs Created by the Author Who's Song a User is Listening to if On a Singlular Song */
3459class AuthorRecentMusic extends WP_Widget {
3460 //Constructor
3461 function AuthorRecentMusic() {
3462 parent::__construct(
3463 'author_recent_music', // Base ID
3464 'Author Recent Music', // Name
3465 array( 'description' => __( 'Display a list of more songs created by the same author if on a singlular song', 'text_domain' ) )
3466 );
3467 }
3468
3469 //Widget Form
3470 function form( $instance ) {
3471 $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
3472 $numberofposts = isset( $instance['numberofposts'] ) ? absint( $instance['numberofposts'] ) : 5;
3473 $show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false;
3474 $showthumbnail = isset( $instance['showthumbnail'] ) ? (bool) $instance['showthumbnail'] : false;
3475 $width = isset( $instance['width'] ) ? esc_attr( $instance['width'] ) : '';
3476 $height = isset( $instance['height'] ) ? esc_attr( $instance['height']) : '';
3477 $alternateImg = isset( $instance['alternateImg'] ) ? esc_attr( $instance['alternateImg'] ) : '';
3478 ?>
3479 <p>
3480 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'wp_widget_plugin' ); ?></label>
3481 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
3482 </p>
3483 <p>
3484 <label for="<?php echo $this->get_field_id( 'numberofposts' ); ?>"><?php _e( 'Number of songs to show:', 'wp_widget_plugin' ); ?></label>
3485 <input id="<?php echo $this->get_field_id( 'numberofposts' ); ?>" name="<?php echo $this->get_field_name( 'numberofposts' ); ?>" type="text" size="3" value="<?php echo $numberofposts; ?>" />
3486 </p>
3487 <p>
3488 <input class="checkbox showthumbnail" id="<?php echo $this->get_field_id( 'showthumbnail' ); ?>" name="<?php echo $this->get_field_name( 'showthumbnail' ); ?>" type="checkbox" <?php checked( $showthumbnail ); ?> /><label for="<?php echo $this->get_field_id( 'showthumbnail' ); ?>"><?php _e( 'Show Thumbnail?', 'wp_widget_plugin' ); ?></label>
3489 </p>
3490 <div class="thumbnailAttr">
3491 <p>
3492 <label for="<?php echo $this->get_field_id( 'width' ); ?>"><?php _e( 'Width: ' ); ?></label>
3493 <input size="3" id="<?php echo $this->get_field_id( 'width' ); ?>" name="<?php echo $this->get_field_name( 'width' ); ?>" type="text" value="<?php echo $width; ?>" /> px
3494 </p>
3495 <p>
3496 <label for="<?php echo $this->get_field_id( 'height' ); ?>"><?php _e( 'Height: ' ); ?></label>
3497 <input size="3" id="<?php echo $this->get_field_id( 'height' ); ?>" name="<?php echo $this->get_field_name( 'height' ); ?>" type="text" value="<?php echo $height; ?>" /> px
3498 </p>
3499 <p>
3500 <label for="<?php echo $this->get_field_id( 'alternateImg' ); ?>"><?php _e( 'Alternate image url:', 'wp_widget_plugin' ); ?></label>
3501 <input class="widefat" id="<?php echo $this->get_field_id( 'alternateImg' ); ?>" name="<?php echo $this->get_field_name( 'alternateImg' ); ?>" type="text" value="<?php echo $alternateImg; ?>" />
3502 </p>
3503 </div>
3504 <p><input class="checkbox" type="checkbox" <?php checked( $show_date ); ?> id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" />
3505 <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Display song date?' ); ?></label></p>
3506 <?php
3507 }
3508
3509 //Widget Update
3510 function update( $new_instance, $old_instance ) {
3511 $old_instance['title'] = $new_instance['title'];
3512 $old_instance['numberofposts'] = isset( $new_instance['numberofposts'] ) ? (int)$new_instance['numberofposts']:'';
3513 $old_instance['showthumbnail'] = isset( $new_instance['showthumbnail'] ) ? (bool) $new_instance['showthumbnail'] : false;
3514 $old_instance['width'] = isset( $new_instance['width'] ) ? $new_instance['width']:'';
3515 $old_instance['height'] = isset( $new_instance['height'] ) ? $new_instance['height']:'';
3516 $old_instance['alternateImg'] = isset( $new_instance['alternateImg'] ) ? $new_instance['alternateImg']:'';
3517 $old_instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false;
3518 return $old_instance;
3519 }
3520
3521 //Widget Display
3522 function widget( $args, $instance ) {
3523 extract( $args );
3524 $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Author Recent Music' );
3525 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
3526 $number = ( ! empty( $instance['numberofposts'] ) ) ? absint( $instance['numberofposts'] ) : 5;
3527 $showthumbnail = isset( $instance['showthumbnail'] ) ? $instance['showthumbnail'] : false;
3528 $width_image = empty( $instance['width'] ) ? '50' : apply_filters( 'widget_image_width', $instance['width'] );
3529 $height_image = empty( $instance['height'] ) ? '50' : apply_filters( 'widget_image_height', $instance['height'] );
3530 $alternateImg = !empty( $instance['alternateImg'] ) ? $instance['alternateImg']:'';
3531 $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
3532
3533 if ( is_single() ) {
3534 global $authordata, $post;
3535 $authors_posts = get_posts( array(
3536 'author' => $authordata->ID,
3537 'post_type' => 'audio',
3538 'post__not_in' => array( $post->ID ),
3539 'posts_per_page' => $number
3540 ) );
3541 if ( count( $authors_posts ) > 0 ) :
3542 ?>
3543 <?php echo $before_widget; ?>
3544 <?php if ( $title )
3545 {
3546 $author = get_the_author_meta( 'display_name', $authordata->ID );
3547 $title = str_replace( '[author]', $author, $title );
3548 echo $before_title . $title . $after_title;
3549 }
3550 ?>
3551 <ul class="author_audio">
3552 <?php foreach ( $authors_posts as $authors_post ) { ?>
3553 <li>
3554 <?php if( $showthumbnail ) : ?>
3555 <div class="author_left" style="width:<?php echo $width_image; ?>px;height:<?php echo $height_image; ?>px;">
3556 <?php
3557 if( $showthumbnail ) {
3558 if( has_post_thumbnail( $authors_post->ID ) ) {
3559 ?>
3560 <a href="<?php echo get_permalink( $authors_post->ID ) ; ?>">
3561 <?php
3562 echo get_the_post_thumbnail( $authors_post->ID, array( $width_image, $height_image ) ); ?>
3563 </a>
3564 <?php
3565 }
3566 elseif( $alternateImg != '') {?>
3567 <a href="<?php echo get_permalink( $authors_post->ID ) ; ?>">
3568 <img src="<?php echo $alternateImg; ?>" width="<?php echo $width_image; ?>" height="<?php echo $height_image; ?>" class="wp-audio-image" />
3569 </a>
3570 <?php }
3571 }?>
3572 </div>
3573 <?php endif; ?>
3574 <div class="author_right">
3575 <a href="<?php echo get_permalink( $authors_post->ID ) ; ?>">
3576 <?php
3577 echo apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ); ?>
3578 </a>
3579 <?php if ( $show_date ) : ?>
3580 <br /><span class="post-date"><small><?php echo date( get_option( 'date_format' ), strtotime( $authors_post->post_date ) ); ?></small></span>
3581 <?php endif; ?>
3582 </div>
3583 </li>
3584 <?php } ?>
3585 </ul>
3586 <?php echo $after_widget; ?>
3587<?php
3588 // Reset the global $the_post as this query will have stomped on it
3589 wp_reset_postdata();
3590 endif;
3591 } // single page condition ends here
3592 }// widget function end here
3593 } // class end tag
3594// register widget
3595add_action( 'widgets_init', create_function( '', 'return register_widget( "AuthorRecentMusic" );' ) );