Ticket #3460: 3460.06.diff
File 3460.06.diff, 39.3 KB (added by , 11 years ago) |
---|
-
bp-activity/bp-activity-functions.php
1575 1575 $activity_obj = $activity_obj->current_comment; 1576 1576 } 1577 1577 1578 if ( 'new_blog_post' == $activity_obj->type || 'new_blog_comment' == $activity_obj->type || 'new_forum_topic' == $activity_obj->type || 'new_forum_post' == $activity_obj->type ) { 1578 $use_primary_link = array( 'new_forum_topic', 'new_forum_post' ); 1579 1580 if ( bp_is_active( 'blogs' ) ) { 1581 // Gets all post types activity actions available 1582 $blogs_post_types = get_object_vars( buddypress()->activity->actions->blogs ); 1583 // Adds them to the array to check. 1584 $use_primary_link = array_merge( $use_primary_link, array_keys( $blogs_post_types ) ); 1585 } 1586 1587 if ( in_array( $activity_obj->type, $use_primary_link ) ) { 1579 1588 $link = $activity_obj->primary_link; 1580 1589 } else { 1581 1590 if ( 'activity_comment' == $activity_obj->type ) { -
bp-activity/bp-activity-template.php
2626 2626 $can_comment = true; 2627 2627 2628 2628 if ( false === $activities_template->disable_blogforum_replies || (int) $activities_template->disable_blogforum_replies ) { 2629 if ( 'new_blog_post' == bp_get_activity_action_name() || 'new_blog_comment' == bp_get_activity_action_name() || 'new_forum_topic' == bp_get_activity_action_name() || 'new_forum_post' == bp_get_activity_action_name() ) 2629 // initialize with forum activity types 2630 $activity_comment_types = array( 'new_forum_topic', 'new_forum_post' ); 2631 2632 if ( bp_is_active( 'blogs' ) ) { 2633 // Gets all post types activity actions available 2634 $blogs_post_types = get_object_vars( buddypress()->activity->actions->blogs ); 2635 // Adds them to the array to check. 2636 $activity_comment_types = array_merge( $activity_comment_types, array_keys( $blogs_post_types ) ); 2637 } 2638 2639 if ( in_array( bp_get_activity_action_name(), $activity_comment_types ) ) 2630 2640 $can_comment = false; 2631 2641 } 2632 2642 -
bp-blogs/bp-blogs-activity.php
106 106 $post_url = add_query_arg( 'p', $activity->secondary_item_id, trailingslashit( $blog_url ) ); 107 107 108 108 $post_title = bp_activity_get_meta( $activity->id, 'post_title' ); 109 $post_type = bp_activity_get_meta( $activity->id, 'post_type' ); 109 110 110 111 // Should only be empty at the time of post creation 111 112 if ( empty( $post_title ) ) { … … 114 115 $post = get_post( $activity->secondary_item_id ); 115 116 if ( is_a( $post, 'WP_Post' ) ) { 116 117 $post_title = $post->post_title; 118 $post_type = $post->post_type; 117 119 bp_activity_update_meta( $activity->id, 'post_title', $post_title ); 120 bp_activity_update_meta( $activity->id, 'post_type', $post_type ); 118 121 } 119 122 120 123 restore_current_blog(); … … 124 127 125 128 $user_link = bp_core_get_userlink( $activity->user_id ); 126 129 130 $post_type_object = get_post_type_object( $post_type ); 131 132 if ( ! empty( $post_type_object->labels->singular_name ) ) { 133 $singular = strtolower( $post_type_object->labels->singular_name ); 134 } else { 135 $singular = __( 'item', 'buddypress' ); 136 } 137 127 138 if ( is_multisite() ) { 128 $action = sprintf( __( '%1$s wrote a new post, %2$s, on the site %3$s', 'buddypress' ), $user_link, $post_link, '<a href="' . esc_url( $blog_url ) . '">' . esc_html( $blog_name ) . '</a>' );139 $action = sprintf( __( '%1$s wrote a new %2$s, %3$s, on the site %4$s', 'buddypress' ), $user_link, esc_html( $singular ), $post_link, '<a href="' . esc_url( $blog_url ) . '">' . esc_html( $blog_name ) . '</a>' ); 129 140 } else { 130 $action = sprintf( __( '%1$s wrote a new post, %2$s', 'buddypress'), $user_link, $post_link );141 $action = sprintf( __( '%1$s wrote a new %2$s, %3$s', 'buddypress' ), esc_html( $singular ), $user_link, $post_link ); 131 142 } 132 143 133 144 // Legacy filter - requires the post object … … 166 177 167 178 $post_url = bp_activity_get_meta( $activity->id, 'post_url' ); 168 179 $post_title = bp_activity_get_meta( $activity->id, 'post_title' ); 180 $post_type = bp_activity_get_meta( $activity->id, 'post_type' ); 169 181 170 182 // Should only be empty at the time of post creation 171 183 if ( empty( $post_url ) || empty( $post_title ) ) { … … 181 193 182 194 if ( is_a( $post, 'WP_Post' ) ) { 183 195 $post_title = $post->post_title; 196 $post_type = $post->post_type; 184 197 bp_activity_update_meta( $activity->id, 'post_title', $post_title ); 198 bp_activity_update_meta( $activity->id, 'post_type', $post_type ); 185 199 } 186 200 } 187 201 … … 191 205 $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>'; 192 206 $user_link = bp_core_get_userlink( $activity->user_id ); 193 207 208 $post_type_object = get_post_type_object( $post_type ); 209 210 if ( ! empty( $post_type_object->labels->singular_name ) ) { 211 $singular = strtolower( $post_type_object->labels->singular_name ); 212 } else { 213 $singular = __( 'item', 'buddypress' ); 214 } 215 194 216 if ( is_multisite() ) { 195 $action = sprintf( __( '%1$s commented on the post, %2$s, on the site %3$s', 'buddypress' ), $user_link, $post_link, '<a href="' . esc_url( $blog_url ) . '">' . esc_html( $blog_name ) . '</a>' );217 $action = sprintf( __( '%1$s commented on the %2$s, %3$s, on the site %4$s', 'buddypress' ), $user_link, esc_html( $singular ), $post_link, '<a href="' . esc_url( $blog_url ) . '">' . esc_html( $blog_name ) . '</a>' ); 196 218 } else { 197 $action = sprintf( __( '%1$s commented on the post, %2$s', 'buddypress' ), $user_link, $post_link );219 $action = sprintf( __( '%1$s commented on the %2$s, %3$s', 'buddypress' ), $user_link, esc_html( $singular ), $post_link ); 198 220 } 199 221 200 222 // Legacy filter - requires the comment object -
bp-blogs/bp-blogs-classes.php
525 525 return $user_blog; 526 526 } 527 527 } 528 529 530 if ( ! class_exists( 'BP_Blogs_Post_Type_Tracker' ) ) : 531 /** 532 * Load BP Blogs Post Type Tracker 533 * 534 * @package BuddyPress 535 * @subpackage blogsClasses 536 * 537 * @since BuddyPress (?) 538 */ 539 class BP_Blogs_Post_Type_Tracker { 540 541 /** 542 * Starts the tracker. 543 * 544 * @access public 545 * @since BuddyPress (?) 546 * 547 * @uses buddypress() to get BuddyPress main instance 548 */ 549 public static function start_tracker() { 550 551 $bp = buddypress(); 552 553 if( empty( $bp->blogs->tracker ) ) { 554 $bp->blogs->tracker = new self; 555 } 556 557 return $bp->blogs->tracker; 558 } 559 560 /** 561 * Constructor method. 562 * 563 * @access public 564 * @since BuddyPress (?) 565 */ 566 public function __construct() { 567 $this->setup_globals(); 568 $this->setup_actions(); 569 } 570 571 /** 572 * Set the trackable post types as a global. 573 * 574 * @access private 575 * @since BuddyPress (?) 576 */ 577 private function setup_globals() { 578 // Activated post types 579 $this->tracked_post_types = bp_trackable_post_types(); 580 $network_active = bp_get_option( 'bp-subsites-enabled-post-types', array() ); 581 582 if ( ! empty( $network_active ) ) { 583 $network_active = array_fill_keys( array_keys( $network_active ), 1 ); 584 $this->tracked_post_types = array_merge( $network_active, $this->tracked_post_types ); 585 } 586 587 // BuddyPress is already tracking posts 588 if ( isset( $this->tracked_post_types['post'] ) ) 589 unset( $this->tracked_post_types['post'] ); 590 } 591 592 /** 593 * Actions. 594 * 595 * @access private 596 * @since BuddyPress (?) 597 */ 598 private function setup_actions() { 599 // Wait till all post types are set 600 add_action( 'init', array( $this, 'setup_post_types' ), 1000 ); 601 } 602 603 /** 604 * Build the activity actions 605 * 606 * @access public 607 * @since BuddyPress (?) 608 */ 609 public function setup_post_types() { 610 $bp = buddypress(); 611 612 $subsite_activated = array(); 613 614 $default_params = array( 615 'singular_name' => __( 'item', 'buddypress' ), 616 'type' => 'new_blog_item', 617 'post_callback' => 'bp_blogs_format_activity_action_new_blog_post', 618 'comment_callback' => 'bp_blogs_format_activity_action_new_blog_comment' 619 ); 620 621 foreach ( $this->tracked_post_types as $post_type => $active ) { 622 // Jump to next if Admin did not activate the tracking 623 if ( empty( $active ) ) 624 continue; 625 626 // Get post type settings 627 $object = get_post_type_object( $post_type ); 628 629 // Jump to next post type after incrementing the subsite activated post types 630 if ( empty( $object ) ) { 631 $subsite_activated[] = $post_type; 632 continue; 633 } 634 635 // This should always be the case for network available post types 636 if ( ! empty( $object->labels->singular_name ) ) { 637 $singular_name = $object->labels->singular_name; 638 $type_post = 'new_blog_' . $post_type; 639 $type_comment = 'new_blog_' . $post_type . '_comment'; 640 641 // This should never happen.. 642 } else { 643 $singular_name = $default_params['singular_name']; 644 $type_post = $default_params['type']; 645 $type_comment = $default_params['type'] . '_comment'; 646 } 647 648 // Do we have a specific callback ? 649 if ( ! empty( $object->bp_tracking['post_callback'] ) ) { 650 $post_callback = $object->bp_tracking['post_callback']; 651 // Use BuddyPress default 652 } else { 653 $post_callback = $default_params['post_callback']; 654 } 655 656 // Set activity actions for post 657 bp_activity_set_action( 658 $bp->blogs->id, 659 $type_post, 660 sprintf( __( 'New %s published', 'buddypress' ), strtolower( $singular_name ) ), 661 $post_callback 662 ); 663 664 if ( ! post_type_supports( $post_type, 'comments' ) ) 665 continue; 666 667 // Do we have a specific callback ? 668 if ( ! empty( $object->bp_tracking['comment_callback'] ) ) { 669 $comment_callback = $object->bp_tracking['comment_callback']; 670 // Use BuddyPress default 671 } else { 672 $comment_callback = $default_params['comment_callback']; 673 } 674 675 // Set activity actions for comments 676 bp_activity_set_action( 677 $bp->blogs->id, 678 $type_comment, 679 sprintf( __( 'New %s comment posted', 'buddypress' ), strtolower( $singular_name ) ), 680 $comment_callback 681 ); 682 683 } 684 685 // Do we have subsite only post type ? 686 if ( ! empty( $subsite_activated ) ) { 687 // Register one global action for all! 688 bp_activity_set_action( 689 $bp->blogs->id, 690 $default_params['type'], 691 sprintf( __( 'New %s published', 'buddypress' ), $default_params['singular_name'] ), 692 $default_params['post_callback'] 693 ); 694 695 bp_activity_set_action( 696 $bp->blogs->id, 697 $default_params['type'] . '_comment', 698 sprintf( __( 'New %s comment posted', 'buddypress' ), $default_params['singular_name'] ), 699 $default_params['post_callback'] 700 ); 701 } 702 } 703 704 } 705 endif; // class_exists check 706 707 // Load the BP Blogs Post Type Tracker 708 add_action( 'bp_blogs_register_activity_actions', array( 'BP_Blogs_Post_Type_Tracker', 'start_tracker' ), 0 ); 709 710 if ( !class_exists( 'BP_Blogs_Admin' ) ) : 711 /** 712 * Load Blogs admin area. 713 * 714 * @package BuddyPress 715 * @subpackage blogsAdministration 716 * 717 * @since BuddyPress (?) 718 */ 719 class BP_Blogs_Admin { 720 721 /** Vars *************************************************************/ 722 723 /** 724 * Current blog id. 725 * 726 * @var string $blog_id 727 */ 728 public $blog_id = ''; 729 730 /** 731 * The list of post types active on the network. 732 * 733 * @var array $network_active 734 */ 735 public $network_active; 736 737 /** 738 * The list of post type to track for the current blog 739 * 740 * @var array $tracked_post_types 741 */ 742 public $tracked_post_types; 743 744 /** 745 * Is this blog trackable ? 746 * 747 * @var boolean 748 */ 749 public $is_public = ''; 750 751 752 /** 753 * Setup BP Blogs Admin. 754 * 755 * @access public 756 * @since BuddyPress (?) 757 * 758 * @uses buddypress() to get BuddyPress main instance 759 */ 760 public static function register_blogs_admin() { 761 if( ! is_admin() || ! bp_core_do_network_admin() ) 762 return; 763 764 $bp = buddypress(); 765 766 if( empty( $bp->blogs->admin ) ) { 767 $bp->blogs->admin = new self; 768 } 769 770 return $bp->blogs->admin; 771 } 772 773 /** 774 * Constructor method. 775 * 776 * @access public 777 * @since BuddyPress (?) 778 */ 779 public function __construct() { 780 $this->setup_globals(); 781 $this->setup_actions(); 782 } 783 784 /** 785 * Set admin-related globals. 786 * 787 * @access private 788 * @since BuddyPress (?) 789 */ 790 private function setup_globals() { 791 792 $this->blog_id = get_current_blog_id(); 793 $this->network_active = bp_trackable_post_types(); 794 $this->tracked_post_types = bp_blogs_blog_trackable_post_type(); 795 $this->is_public = get_option( 'blog_public' ); 796 $this->capability = ! bp_restrict_blogs_tracking_visibility() ? 'manage_options' : 'manage_sites'; 797 798 } 799 800 /** 801 * Set admin-related actions and filters. 802 * 803 * @access private 804 * @since BuddyPress (?) 805 */ 806 private function setup_actions() { 807 // Bail if blog is not trackable 808 if ( empty( $this->is_public ) ) 809 return; 810 811 if( $this->blog_id == bp_get_root_blog_id() ) 812 return; 813 814 // Add an option page to blog settings 815 add_action( 'admin_menu', array( $this, 'admin_menus' ) ); 816 817 // Register the blog tracking settings 818 add_action( 'bp_register_admin_settings', array( $this, 'blog_settings' ) ); 819 } 820 821 /** 822 * Create the options sub menu. 823 * 824 * @access public 825 * @since BuddyPress (?) 826 * 827 * @uses add_options_page() To add the Site tracking submenu. 828 */ 829 public function admin_menus() { 830 831 $hook = add_options_page( 832 __( 'Network Tracking', 'buddypress' ), 833 __( 'Network Tracking', 'buddypress' ), 834 $this->capability, 835 'bp-tracking', 836 array( &$this, 'tracking_settings' ) 837 ); 838 839 add_action( "admin_head-$hook", array( $this, 'set_network_post_types' ) ); 840 841 } 842 843 /** 844 * Create the settings page. 845 * 846 * @access public 847 * @since BuddyPress (?) 848 */ 849 public function tracking_settings() { 850 if ( ! current_user_can( $this->capability ) ) { 851 die( '-1' ); 852 } 853 ?> 854 <div class="wrap"> 855 <?php screen_icon( 'buddypress' ); ?> 856 857 <h2><?php esc_html_e( 'Settings', 'buddypress' ); ?></h2> 858 859 <form action="options.php" method="post"> 860 861 <?php settings_fields( 'buddypress_blog' ); ?> 862 863 <?php do_settings_sections( 'buddypress_blog' ); ?> 864 865 <p class="submit"> 866 <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e( 'Save Settings', 'buddypress' ); ?>" /> 867 </p> 868 </form> 869 </div> 870 <?php 871 } 872 873 /** 874 * Create the settings section & fields. 875 * 876 * @access public 877 * @since BuddyPress (?) 878 */ 879 public function blog_settings() { 880 // Add the main section 881 add_settings_section( 882 'bp_blog', 883 '', 884 array( &$this, 'main_section_callback' ), 885 'buddypress_blog' 886 ); 887 888 // Add the site tracking section 889 add_settings_section( 890 'bp_tracking', 891 __( 'Site Tracking Settings', 'buddypress' ), 892 array( &$this, 'tracking_section_callback' ), 893 'buddypress_blog' 894 ); 895 896 // Add the tracking setting 897 add_settings_field( 898 'bp-enabled-post-types', 899 __( 'List of post types to track', 'buddypress' ), 900 array( &$this, 'post_types_setting_callback' ), 901 'buddypress_blog', 902 'bp_tracking' 903 ); 904 905 register_setting( 906 'buddypress_blog', 907 'bp-enabled-post-types', 908 array( &$this, 'post_types_sanitize_callback' ) 909 ); 910 } 911 912 /** 913 * Output the main section callback 914 * 915 * @access public 916 * @since BuddyPress (?) 917 */ 918 public function main_section_callback() {} 919 920 /** 921 * Output the tracking section callback 922 * 923 * @access public 924 * @since BuddyPress (?) 925 */ 926 public function tracking_section_callback() { 927 ?> 928 <p class="description"> 929 <?php esc_html_e( 'List of the post types active for tracking on the network:', 'buddypress' ) ;?> 930 931 <ol> 932 <?php foreach ( $this->network_active as $post_type => $active ) : 933 if ( empty( $active ) ) 934 continue; 935 ?> 936 937 <li><?php echo esc_html( ucfirst( $post_type ) );?></li> 938 939 <?php endforeach; ?> 940 </ol> 941 942 </p> 943 <p class="description"><?php printf( __( 'You can disable the tracking of your site by <a href="%s">discouraging</a> search engines from indexing your site', 'buddypress' ), admin_url( 'options-reading.php#blog_public' ) ); ?></p> 944 <p class="description"><?php esc_html_e( 'Manage your site post types by enabling, disabling the checkboxes', 'buddypress' ) ;?></p> 945 <?php 946 } 947 948 /** 949 * Output the tracking section callback 950 * 951 * @access public 952 * @since BuddyPress (?) 953 * 954 * @uses bp_admin_setting_callback_post_types_tracked() to get the output 955 */ 956 public function post_types_setting_callback() { 957 return bp_admin_setting_callback_post_types_tracked( $this->tracked_post_types ); 958 } 959 960 /** 961 * Sanitize the tracking setting 962 * 963 * @access public 964 * @since BuddyPress (?) 965 * 966 * @uses bp_admin_sanitize_callback_post_types_tracked() to sanitize the option 967 */ 968 public function post_types_sanitize_callback( $option = array() ) { 969 return bp_admin_sanitize_callback_post_types_tracked( $option ); 970 } 971 972 /** 973 * Saves an option listing all the post types activated on the network 974 * 975 * @access public 976 * @since BuddyPress (?) 977 */ 978 public function set_network_post_types() { 979 if ( ! current_user_can( $this->capability ) ) { 980 die( '-1' ); 981 } 982 // Bail if no settings were updated 983 if ( empty( $_GET['settings-updated'] ) || 'true' != $_GET['settings-updated'] ) 984 return; 985 986 // the network option 987 $active_subsites_post_types = bp_get_option( 'bp-subsites-enabled-post-types', array() ); 988 $before_change = $active_subsites_post_types; 989 990 // Should we update ? 991 $subsite_compare = array_diff_key( $active_subsites_post_types, $this->tracked_post_types ); 992 $network_compare = array_diff_key( $this->tracked_post_types, $active_subsites_post_types ); 993 994 if ( ! empty( $this->tracked_post_types ) && ! empty( $network_compare ) ) { 995 foreach( array_keys( $this->tracked_post_types ) as $post ) { 996 997 if ( 'post' == $post ) 998 continue; 999 1000 if ( empty( $active_subsites_post_types[ $post ] ) || ! in_array( $this->blog_id, $active_subsites_post_types[ $post ] ) ) 1001 $active_subsites_post_types[ $post ][] = $this->blog_id; 1002 } 1003 } 1004 1005 if ( ! empty( $active_subsites_post_types ) && ! empty( $subsite_compare ) ) { 1006 foreach( array_keys( $active_subsites_post_types ) as $post ) { 1007 1008 if ( in_array( $this->blog_id, $active_subsites_post_types[ $post ] ) ) { 1009 $active_subsites_post_types[ $post ] = array_diff( $active_subsites_post_types[ $post ], array( $this->blog_id ) ); 1010 } 1011 1012 if ( empty( $active_subsites_post_types[ $post ] ) ) 1013 unset( $active_subsites_post_types[ $post ] ); 1014 } 1015 } 1016 1017 if ( $before_change != $active_subsites_post_types ) { 1018 bp_update_option( 'bp-subsites-enabled-post-types', $active_subsites_post_types ); 1019 } 1020 } 1021 1022 } 1023 endif; // class_exists check 1024 1025 // Load the BP Blogs admin 1026 add_action( 'bp_init', array( 'BP_Blogs_Admin','register_blogs_admin' ) ); -
bp-blogs/bp-blogs-functions.php
161 161 } 162 162 163 163 /** 164 * Gets the trackable post type for a given block. 165 * 166 * @since BuddyPress (?) 167 * 168 * @uses bp_trackable_post_types() 169 * @uses apply_filters() 170 * 171 * @param array $default default post types. 172 * @param int $blog_id the blog the post type is registered to. 173 * @return array the trackable post type for the given block. 174 */ 175 function bp_blogs_blog_trackable_post_type( $default = array(), $blog_id = 0 ) { 176 if ( empty( $blog_id ) ) 177 $blog_id = get_current_blog_id(); 178 179 if ( empty( $default) ) 180 $default = array( 'post' => 1 ); 181 182 $default = array_merge( bp_trackable_post_types(), $default ); 183 184 return (array) apply_filters( 'bp_blogs_blog_trackable_post_types', (array) get_blog_option( $blog_id, 'bp-enabled-post-types', $default ), $blog_id ); 185 } 186 187 /** 188 * Check whether a given blog post type should be tracked by the Blogs component. 189 * 190 * If $blog_id is provided, the developer can restrict a given blog post type from 191 * being trackable. 192 * 193 * @since BuddyPress (?) 194 * 195 * @uses bp_trackable_post_types() 196 * @uses apply_filters() 197 * 198 * @param string $post_type the post type being checked. 199 * @param int $blog_id the blog the post type is registered to. 200 * @return bool True if the post type is trackable, otherwise false. 201 */ 202 function bp_blogs_is_blog_post_type_trackable( $post_type = '', $blog_id = 0 ) { 203 /** 204 * If blog id is not root_blog_id, get the current blog settings instead of network one 205 */ 206 if ( $blog_id != bp_get_root_blog_id() ) { 207 $trackable = (array) apply_filters( 'bp_blogs_is_blog_post_type_trackable', bp_blogs_blog_trackable_post_type( array(), $blog_id ), $blog_id ); 208 } else { 209 $trackable = (array) apply_filters( 'bp_blogs_is_blog_post_type_trackable', bp_trackable_post_types(), $blog_id ); 210 } 211 212 // BackCompat 213 $legacy_post_type_filter = apply_filters( 'bp_blogs_record_post_post_types', array() ); 214 $legacy_comment_filter = apply_filters( 'bp_blogs_record_comment_post_types', array() ); 215 $legacy_post_type_filter = array_merge( $legacy_post_type_filter, $legacy_comment_filter ); 216 217 if ( ! empty( $legacy_post_type_filter ) ) { 218 $legacy_post_type_filter = array_fill_keys( $legacy_post_type_filter, 1 ); 219 220 // Merge the two arrays making sure the setting saved for the post type will be the final value 221 $trackable = array_merge( $legacy_post_type_filter, $trackable ); 222 } 223 224 return ! empty( $trackable[ $post_type ] ); 225 } 226 227 /** 164 228 * Make BuddyPress aware of a new site so that it can track its activity. 165 229 * 166 230 * @since BuddyPress (1.0.0) … … 318 382 if ( (int) $blog_id == $tags_blog_id && apply_filters( 'bp_blogs_block_sitewide_tags_activity', true ) ) 319 383 return false; 320 384 321 // Don't record this if it's not a post322 if ( ! in_array( $post->post_type, apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) )) )385 // Don't record this if the post type is not trackable 386 if ( ! bp_blogs_is_blog_post_type_trackable( $post->post_type, $blog_id ) ) 323 387 return false; 324 388 325 389 $is_blog_public = apply_filters( 'bp_is_blog_public', (int)get_blog_option( $blog_id, 'blog_public' ) ); … … 334 398 trailingslashit( get_home_url( $blog_id ) ) 335 399 ); 336 400 401 // Default 402 $action_args = array( 403 'action' => 'new_blog_item', 404 'singular_name' => __( 'item', 'buddypress' ), 405 ); 406 407 /** 408 * Avoiding this part would display the action instead of 409 * the translatable string introduced in https://buddypress.trac.wordpress.org/changeset/8126 410 */ 411 $is_subsite_post_type = ! in_array( 412 $post->post_type, 413 array_keys( 414 array_merge( bp_trackable_post_types(), array( 'page' => 1 ) ) 415 ) 416 ); 417 418 if ( empty( $is_subsite_post_type ) ) { 419 $post_type_object = get_post_type_object( $post->post_type ); 420 $action_args['action'] = 'new_blog_' . $post->post_type; 421 422 if ( ! empty( $post_type_object->labels->singular_name ) ) 423 $action_args['singular_name'] = strtolower( $post_type_object->labels->singular_name ); 424 } 425 337 426 if ( is_multisite() ) 338 $activity_action = sprintf( __( '%1$s wrote a new post, %2$s, on the site %3$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' );427 $activity_action = sprintf( __( '%1$s wrote a new %2$s, %3$s, on the site %4$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), $action_args['singular_name'], '<a href="' . $post_permalink . '">' . $post->post_title . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' ); 339 428 else 340 $activity_action = sprintf( __( '%1$s wrote a new post, %2$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );429 $activity_action = sprintf( __( '%1$s wrote a new %2$s, %3$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), $action_args['singular_name'], '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' ); 341 430 342 431 // Make sure there's not an existing entry for this post (prevent bumping) 343 432 if ( bp_is_active( 'activity' ) ) { 344 433 $existing = bp_activity_get( array( 345 434 'filter' => array( 346 'action' => 'new_blog_post',435 'action' => $action_args['action'], 347 436 'primary_id' => $blog_id, 348 437 'secondary_id' => $post_id, 349 438 ) … … 356 445 357 446 $activity_content = $post->post_content; 358 447 359 bp_blogs_record_activity( array(448 $activity_id = bp_blogs_record_activity( array( 360 449 'user_id' => (int) $post->post_author, 361 'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, $post, $post_permalink ), 362 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ), 363 'type' => 'new_blog_post', 450 'action' => apply_filters( "bp_blogs_activity_new_{$post->post_type}_action", $activity_action, $post, $post_permalink ), 451 'content' => apply_filters( "bp_blogs_activity_new_{$post->post_type}_content", $activity_content, $post, $post_permalink ), 452 'primary_link' => apply_filters( "bp_blogs_activity_new_{$post->post_type}_primary_link", $post_permalink, $post_id ), 453 'type' => $action_args['action'], 364 454 'item_id' => $blog_id, 365 455 'secondary_item_id' => $post_id, 366 456 'recorded_time' => $post->post_date_gmt, 367 457 )); 458 459 if( ! empty( $is_subsite_post_type ) ) { 460 bp_activity_update_meta( $activity_id, 'post_title', $post->post_title ); 461 bp_activity_update_meta( $activity_id, 'post_type', $post->post_type ); 462 } 368 463 } 369 464 370 465 // Update the blogs last activity … … 428 523 if ( !empty( $recorded_comment->post->post_password ) ) 429 524 return false; 430 525 431 // Don't record activity if the comment's associated post isn't a WordPress Post432 if ( ! in_array( $recorded_comment->post->post_type, apply_filters( 'bp_blogs_record_comment_post_types', array( 'post' ) )) )526 // Don't record this if the post type has not been set by administrator to be tracked 527 if ( ! bp_blogs_is_blog_post_type_trackable( $recorded_comment->post->post_type, $blog_id ) ) 433 528 return false; 434 529 435 530 $is_blog_public = apply_filters( 'bp_is_blog_public', (int)get_blog_option( $blog_id, 'blog_public' ) ); … … 441 536 $post_permalink = get_permalink( $recorded_comment->comment_post_ID ); 442 537 $comment_link = get_comment_link( $recorded_comment->comment_ID ); 443 538 539 // Default 540 $action_args = array( 541 'action' => 'new_blog_item_comment', 542 'singular_name' => __( 'item', 'buddypress' ), 543 ); 544 545 /** 546 * Avoiding this part would display the action instead of 547 * the translatable string introduced in https://buddypress.trac.wordpress.org/changeset/8126 548 */ 549 $is_subsite_post_type = ! in_array( 550 $recorded_comment->post->post_type, 551 array_keys( 552 array_merge( bp_trackable_post_types(), array( 'page' => 1 ) ) 553 ) 554 ); 555 556 if ( empty( $is_subsite_post_type ) ) { 557 $post_type_object = get_post_type_object( $recorded_comment->post->post_type ); 558 $action_args['action'] = 'new_blog_' . $recorded_comment->post->post_type . '_comment'; 559 560 if ( ! empty( $post_type_object->labels->singular_name ) ) 561 $action_args['singular_name'] = strtolower( $post_type_object->labels->singular_name ); 562 } 563 564 if ( 'post' == $recorded_comment->post->post_type ) { 565 $action_args['action'] = 'new_blog_comment'; 566 } 567 444 568 // Prepare to record in activity streams 445 569 if ( is_multisite() ) 446 $activity_action = sprintf( __( '%1$s commented on the post, %2$s, on the site %3$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' );570 $activity_action = sprintf( __( '%1$s commented on the %2$s, %3$s, on the site %4$s', 'buddypress' ), bp_core_get_userlink( $user_id ), $action_args['singular_name'], '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' ); 447 571 else 448 $activity_action = sprintf( __( '%1$s commented on the post, %2$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' );572 $activity_action = sprintf( __( '%1$s commented on the %2$s, %3$s', 'buddypress' ), bp_core_get_userlink( $user_id ), $action_args['singular_name'], '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' ); 449 573 450 574 $activity_content = $recorded_comment->comment_content; 451 575 452 576 // Record in activity streams 453 bp_blogs_record_activity( array(577 $activity_id = bp_blogs_record_activity( array( 454 578 'user_id' => $user_id, 455 'content' => apply_filters_ref_array( 'bp_blogs_activity_new_comment_content', array( $activity_content, &$recorded_comment, $comment_link ) ), 456 'primary_link' => apply_filters_ref_array( 'bp_blogs_activity_new_comment_primary_link', array( $comment_link, &$recorded_comment ) ), 457 'type' => 'new_blog_comment', 579 'action' => apply_filters_ref_array( "bp_blogs_activity_new_{$recorded_comment->post->post_type}_action", array( $activity_action, &$recorded_comment, $comment_link ) ), 580 'content' => apply_filters_ref_array( "bp_blogs_activity_new_{$recorded_comment->post->post_type}_content", array( $activity_content, &$recorded_comment, $comment_link ) ), 581 'primary_link' => apply_filters_ref_array( "bp_blogs_activity_new_{$recorded_comment->post->post_type}_primary_link", array( $comment_link, &$recorded_comment ) ), 582 'type' => $action_args['action'], 458 583 'item_id' => $blog_id, 459 584 'secondary_item_id' => $comment_id, 460 585 'recorded_time' => $recorded_comment->comment_date_gmt 461 586 ) ); 462 587 588 if( ! empty( $is_subsite_post_type ) ) { 589 $post_url = add_query_arg( 590 'p', 591 $recorded_comment->comment_post_ID, 592 trailingslashit( get_home_url( $blog_id ) ) 593 ); 594 bp_activity_update_meta( $activity_id, 'post_url', $post_url ); 595 bp_activity_update_meta( $activity_id, 'post_title', $recorded_comment->post->post_title ); 596 bp_activity_update_meta( $activity_id, 'post_type', $recorded_comment->post->post_type ); 597 } 598 463 599 // Update the blogs last active date 464 600 bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() ); 465 601 } -
bp-blogs/bp-blogs-template.php
1292 1292 // Filter and return 1293 1293 return apply_filters( 'bp_blogs_get_profile_stats', $r['output'], $r ); 1294 1294 } 1295 1296 /** 1297 * Adds the available post types actions to activity filters 1298 * 1299 * As in bp-legacy or bp-default templates the regular post type 1300 * is already added we'll need to remove it from these options. 1301 * Leaving it this way for backcompat theme purpose. But all 1302 * post types should be handled there in the future.. 1303 * 1304 * @return string html output 1305 */ 1306 function bp_blogs_post_types_activity_options() { 1307 1308 $blogs_legacy_actions = array( 'new_blog_post', 'new_blog_comment' ); 1309 $blogs_post_types_actions = buddypress()->activity->actions->blogs; 1310 1311 foreach ( $blogs_post_types_actions as $action ) { 1312 if ( in_array( $action['key'], $blogs_legacy_actions ) ) 1313 continue; 1314 ?> 1315 <option value="<?php echo esc_attr( $action['key'] ) ;?>"><?php echo esc_html( $action['value'] ) ;?></option> 1316 <?php 1317 } 1318 } 1319 add_action( 'bp_activity_filter_options', 'bp_blogs_post_types_activity_options' ); 1320 add_action( 'bp_member_activity_filter_options', 'bp_blogs_post_types_activity_options' ); -
bp-core/admin/bp-core-settings.php
211 211 <?php 212 212 } 213 213 214 /** Blogs custom post types Section **********************************************/ 215 216 /** 217 * Displays a message about the trackable post types in case BuddyPress is network activated 218 * 219 * @since BuddyPress (?) 220 * @uses bp_core_do_network_admin() to check if BuddyPress is network activated 221 */ 222 function bp_admin_setting_callback_blogs_section() { 223 if ( ! bp_core_do_network_admin() ) 224 return; 225 ?> 226 <p class="description"><?php _e( 'In case a Post type is only active on a child blog, its tracking needs to be set in the blog Administration', 'buddypress' );?></p> 227 <?php 228 } 229 230 /** 231 * Allow the Admin to define the post types to track in activity stream 232 * 233 * @since BuddyPress (?) 234 * 235 * @uses get_post_types() to list the show_in_nav_menus enabled post types 236 * @uses checked() To display the checked attribute 237 * @uses post_type_supports() to check for bp_tracking support 238 */ 239 function bp_admin_setting_callback_post_types_tracked( $setting = '' ) { 240 /** 241 * Using show_in_nav_menus argument avoids the inclusion of the attachment post type 242 * if show_in_nav_menus is not defined it defaults to the value of public arguments 243 */ 244 $post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'objects' ); 245 246 // Building an array to compare with the array saved in bp-enabled-post-types option 247 $compare = array_fill_keys( array_keys( $post_types ), 0 ); 248 249 if ( empty( $setting ) ) 250 $setting = bp_trackable_post_types(); 251 252 // Merge the two arrays making sure the setting saved for the post type will be the final value 253 $db_post_types = array_merge( $compare, $setting ); 254 255 if ( empty( $db_post_types ) ) 256 return; 257 258 foreach ( $post_types as $post_type => $arguments ) { 259 $readonly = ( 'post' == $post_type ) ? 'disabled' : ''; 260 ?> 261 262 <input id="bp-enabled-post-types-<?php echo $post_type;?>" name="bp-enabled-post-types[<?php echo $post_type;?>]" type="checkbox" value="1" <?php checked( $db_post_types[ $post_type ] ); ?> <?php echo $readonly;?>/> 263 <label for="bp-enabled-post-types-<?php echo $post_type;?>"><?php echo $arguments->labels->name ?></label> 264 265 <?php 266 } 267 268 } 269 270 /** 271 * Allow regular admins to set the post type to track on network config 272 * 273 * @since BuddyPress (1.6) 274 * 275 * @uses checked() To display the checked attribute 276 */ 277 function bp_admin_setting_callback_blogs_tracking_visibility() { 278 ?> 279 280 <input id="bp-restrict-blogs-tracking" name="bp-restrict-blogs-tracking" type="checkbox" value="1" <?php checked( !bp_restrict_blogs_tracking_visibility( false ) ); ?> /> 281 <label for="bp-restrict-blogs-tracking"><?php _e( 'Enable Blogs tracking settings for Administrators', 'buddypress' ); ?></label> 282 283 <?php 284 } 285 286 287 /** 288 * Sanitization for bp-enabled-post-types 289 * 290 * @since BuddyPress (?) 291 */ 292 function bp_admin_sanitize_callback_post_types_tracked( $value = array() ) { 293 // Post is legacy : always tracked. 294 $tracked = array( 'post' => 1 ); 295 296 if( is_array( $value ) ) 297 $tracked = array_merge( $tracked, $value ); 298 299 return array_map( 'absint', $tracked ); 300 } 301 214 302 /** Forums Section ************************************************************/ 215 303 216 304 /** … … 316 404 'bp_disable_blogforum_comments', 317 405 'bp-disable-profile-sync', 318 406 'bp_restrict_group_creation', 407 'bp-restrict-blogs-tracking', 319 408 'hide-loggedout-adminbar', 320 409 ); 321 410 -
bp-core/bp-core-admin.php
389 389 add_settings_field( 'bp-disable-avatar-uploads', __( 'Avatar Uploads', 'buddypress' ), 'bp_admin_setting_callback_avatar_uploads', 'buddypress', $avatar_setting ); 390 390 register_setting ( 'buddypress', 'bp-disable-avatar-uploads', 'intval' ); 391 391 } 392 393 /** Blogs Section **************************************************/ 394 395 if ( bp_is_active( 'blogs' ) ) { 396 397 // Add the main section 398 add_settings_section( 'bp_blogs', __( 'Site Tracking Settings', 'buddypress' ), 'bp_admin_setting_callback_blogs_section', 'buddypress' ); 399 400 // Post type tracking: list of items to track 401 add_settings_field( 'bp-enabled-post-types', __( 'List of post types to track', 'buddypress' ), 'bp_admin_setting_callback_post_types_tracked', 'buddypress', 'bp_blogs' ); 402 register_setting ( 'buddypress', 'bp-enabled-post-types', 'bp_admin_sanitize_callback_post_types_tracked' ); 403 404 if ( bp_core_do_network_admin() ) { 405 // Post type tracking: list of items to track 406 add_settings_field( 'bp-restrict-blogs-tracking', __( 'Blogs tracking settings access', 'buddypress' ), 'bp_admin_setting_callback_blogs_tracking_visibility', 'buddypress', 'bp_blogs' ); 407 register_setting ( 'buddypress', 'bp-restrict-blogs-tracking', 'intval' ); 408 } 409 } 392 410 } 393 411 394 412 /** -
bp-core/bp-core-options.php
61 61 // Allow comments on blog and forum activity items 62 62 'bp-disable-blogforum-comments' => true, 63 63 64 // Restrict blog tracking visibility to super admins 65 'bp-restrict-blogs-tracking' => false, 66 64 67 // The ID for the current theme package. 65 68 '_bp_theme_package_id' => 'legacy', 66 69 … … 505 508 return (bool) apply_filters( 'bp_disable_blogforum_comments', (bool) bp_get_option( 'bp-disable-blogforum-comments', $default ) ); 506 509 } 507 510 511 /** 512 * What are the registered post types trackable in activity streams? 513 * 514 * @since BuddyPress (?) 515 * 516 * @uses bp_get_option() To get the blog/forum comments option. 517 * 518 * @param array $default Optional. Fallback value if not found in the database. 519 * Default: array(). 520 * @return bool True if activity comments are disabled for blog and forum 521 * items, otherwise false. 522 */ 523 function bp_trackable_post_types( $default = array( 'post' => 1 ) ) { 524 return (array) apply_filters( 'bp_trackable_post_types', (array) bp_get_option( 'bp-enabled-post-types', $default ) ); 525 } 526 508 527 /** 528 * Is Blog tracking restricted to Super Admins ? 529 * 530 * @since BuddyPress (?) 531 * 532 * @uses bp_get_option() To get the blog tracking visibility. 533 * 534 * @param bool $default Optional. Fallback value if not found in the database. 535 * Default: true. 536 * @return bool True if blog tracking visibility is restricted, otherwise false. 537 */ 538 function bp_restrict_blogs_tracking_visibility( $default = true ) { 539 return (bool) apply_filters( 'bp_restrict_blogs_tracking_visibility', (bool) bp_get_option( 'bp-restrict-blogs-tracking', $default ) ); 540 } 541 542 /** 509 543 * Is group creation turned off? 510 544 * 511 545 * @since BuddyPress (1.6.0)