Changeset 10356 for trunk/src/bp-core/bp-core-filters.php
- Timestamp:
- 11/15/2015 07:57:03 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/src/bp-core/bp-core-filters.php (modified) (46 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-filters.php
r10276 r10356 44 44 add_filter( 'map_meta_cap', 'bp_map_meta_caps', 10, 4 ); 45 45 46 // Add some filters to feedback messages 46 // Add some filters to feedback messages. 47 47 add_filter( 'bp_core_render_message_content', 'wptexturize' ); 48 48 add_filter( 'bp_core_render_message_content', 'convert_smilies' ); … … 62 62 add_filter( 'bp_template_include', 'bp_template_include_theme_compat', 4, 2 ); 63 63 64 // Filter BuddyPress template locations 64 // Filter BuddyPress template locations. 65 65 add_filter( 'bp_get_template_stack', 'bp_add_template_stack_locations' ); 66 66 67 // Turn comments off for BuddyPress pages 67 // Turn comments off for BuddyPress pages. 68 68 add_filter( 'comments_open', 'bp_comments_open', 10, 2 ); 69 69 … … 75 75 * @param array $pages List of excluded page IDs, as passed to the 76 76 * 'wp_list_pages_excludes' filter. 77 *78 77 * @return array The exclude list, with BP's pages added. 79 78 */ 80 79 function bp_core_exclude_pages( $pages = array() ) { 81 80 82 // Bail if not the root blog 81 // Bail if not the root blog. 83 82 if ( ! bp_is_root_blog() ) 84 83 return $pages; … … 115 114 * 116 115 * @param object|null $object The post type object used in the meta box. 117 *118 116 * @return object|null The $object, with a query argument to remove register and activate pages id. 119 117 */ 120 118 function bp_core_exclude_pages_from_nav_menu_admin( $object = null ) { 121 119 122 // Bail if not the root blog 120 // Bail if not the root blog. 123 121 if ( ! bp_is_root_blog() ) { 124 122 return $object; … … 160 158 * @param array $retval CSS classes for the current menu page in the menu. 161 159 * @param WP_Post $page The page properties for the current menu item. 162 *163 160 * @return array 164 161 */ … … 170 167 $page_id = false; 171 168 172 // loop against all BP component pages169 // Loop against all BP component pages. 173 170 foreach ( (array) buddypress()->pages as $component => $bp_page ) { 174 // handles the majority of components171 // Handles the majority of components. 175 172 if ( bp_is_current_component( $component ) ) { 176 173 $page_id = (int) $bp_page->id; 177 174 } 178 175 179 // stop if not on a user page176 // Stop if not on a user page. 180 177 if ( ! bp_is_user() && ! empty( $page_id ) ) { 181 178 break; 182 179 } 183 180 184 // members component requires an explicit check due to overlapping components181 // Members component requires an explicit check due to overlapping components. 185 182 if ( bp_is_user() && 'members' === $component ) { 186 183 $page_id = (int) $bp_page->id; … … 189 186 } 190 187 191 // duplicate some logic from Walker_Page::start_el() to highlight menu items188 // Duplicate some logic from Walker_Page::start_el() to highlight menu items. 192 189 if ( ! empty( $page_id ) ) { 193 190 $_bp_page = get_post( $page_id ); … … 218 215 * @param array $retval CSS classes for the current nav menu item in the menu. 219 216 * @param WP_Post $item The properties for the current nav menu item. 220 *221 217 * @return array 222 218 */ … … 227 223 } 228 224 229 // get the WP page225 // Get the WP page. 230 226 $page = get_post( $item->object_id ); 231 227 232 // see if we should add our highlight CSS classes for the page228 // See if we should add our highlight CSS classes for the page. 233 229 $retval = bp_core_menu_highlight_parent_page( $retval, $page ); 234 230 … … 262 258 * @param array $comments The array of comments supplied to the comments template. 263 259 * @param int $post_id The post ID. 264 *265 260 * @return array $comments The modified comment array. 266 261 */ … … 305 300 * @param WP_User $user The WP_User object corresponding to a successfully 306 301 * logged-in user. Otherwise a WP_Error object. 307 *308 302 * @return string The redirect URL. 309 303 */ 310 304 function bp_core_login_redirect( $redirect_to, $redirect_to_raw, $user ) { 311 305 312 // Only modify the redirect if we're on the main BP blog 306 // Only modify the redirect if we're on the main BP blog. 313 307 if ( !bp_is_root_blog() ) { 314 308 return $redirect_to; 315 309 } 316 310 317 // Only modify the redirect once the user is logged in 311 // Only modify the redirect once the user is logged in. 318 312 if ( !is_a( $user, 'WP_User' ) ) { 319 313 return $redirect_to; … … 340 334 // If a 'redirect_to' parameter has been passed that contains 'wp-admin', verify that the 341 335 // logged-in user has any business to conduct in the Dashboard before allowing the 342 // redirect to go through 336 // redirect to go through. 343 337 if ( !empty( $redirect_to ) && ( false === strpos( $redirect_to, 'wp-admin' ) || user_can( $user, 'edit_posts' ) ) ) { 344 338 return $redirect_to; … … 370 364 * 371 365 * @param string $welcome_email Complete email passed through WordPress. 372 *373 366 * @return string Filtered $welcome_email with the password replaced 374 367 * by '[User Set]'. … … 376 369 function bp_core_filter_user_welcome_email( $welcome_email ) { 377 370 378 // Don't touch the email when a user is registered by the site admin 371 // Don't touch the email when a user is registered by the site admin. 379 372 if ( ( is_admin() || is_network_admin() ) && buddypress()->members->admin->signups_page != get_current_screen()->id ) { 380 373 return $welcome_email; … … 385 378 } 386 379 387 // Don't touch the email if we don't have a custom registration template 380 // Don't touch the email if we don't have a custom registration template. 388 381 if ( ! bp_has_custom_signup_page() ) { 389 382 return $welcome_email; … … 408 401 * @param int $user_id ID of the user joining. 409 402 * @param string $password Password of user. 410 *411 403 * @return string Filtered $welcome_email with $password replaced by '[User Set]'. 412 404 */ 413 405 function bp_core_filter_blog_welcome_email( $welcome_email, $blog_id, $user_id, $password ) { 414 406 415 // Don't touch the email when a user is registered by the site admin 407 // Don't touch the email when a user is registered by the site admin. 416 408 if ( ( is_admin() || is_network_admin() ) && buddypress()->members->admin->signups_page != get_current_screen()->id ) { 417 409 return $welcome_email; 418 410 } 419 411 420 // Don't touch the email if we don't have a custom registration template 412 // Don't touch the email if we don't have a custom registration template. 421 413 if ( ! bp_has_custom_signup_page() ) 422 414 return $welcome_email; … … 440 432 * @param string $user The user's login name. 441 433 * @param string $user_email The user's email address. 442 * @param string $key The activation key created in wpmu_signup_blog() 434 * @param string $key The activation key created in wpmu_signup_blog(). 443 435 * @param array $meta By default, contains the requested privacy setting and 444 436 * lang_id. 445 *446 437 * @return bool True on success, false on failure. 447 438 */ 448 439 function bp_core_activation_signup_blog_notification( $domain, $path, $title, $user, $user_email, $key, $meta ) { 449 440 450 // Set up activation link 441 // Set up activation link. 451 442 $activate_url = bp_get_activation_page() ."?key=$key"; 452 443 $activate_url = esc_url( $activate_url ); 453 444 454 // Email contents 445 // Email contents. 455 446 $message = sprintf( __( "%1\$s,\n\n\n\nThanks for registering! To complete the activation of your account and blog, please click the following link:\n\n%2\$s\n\n\n\nAfter you activate, you can visit your blog here:\n\n%3\$s", 'buddypress' ), $user, $activate_url, esc_url( "http://{$domain}{$path}" ) ); 456 447 $subject = bp_get_email_subject( array( 'text' => sprintf( __( 'Activate %s', 'buddypress' ), 'http://' . $domain . $path ) ) ); … … 504 495 $message = apply_filters( 'bp_core_activation_signup_blog_notification_message', $message, $domain, $path, $title, $user, $user_email, $key, $meta ); 505 496 506 // Send the email 497 // Send the email. 507 498 wp_mail( $to, $subject, $message ); 508 499 509 // Set up the $admin_email to pass to the filter 500 // Set up the $admin_email to pass to the filter. 510 501 $admin_email = bp_get_option( 'admin_email' ); 511 502 … … 528 519 do_action( 'bp_core_sent_blog_signup_email', $admin_email, $subject, $message, $domain, $path, $title, $user, $user_email, $key, $meta ); 529 520 530 // Return false to stop the original WPMU function from continuing 521 // Return false to stop the original WPMU function from continuing. 531 522 return false; 532 523 } … … 540 531 * @param string $user The user's login name. 541 532 * @param string $user_email The user's email address. 542 * @param string $key The activation key created in wpmu_signup_user() 533 * @param string $key The activation key created in wpmu_signup_user(). 543 534 * @param array $meta By default, an empty array. 544 *545 535 * @return bool|string True on success, false on failure. 546 536 */ … … 548 538 549 539 if ( is_admin() ) { 550 // If the user is created from the WordPress Add User screen, don't send BuddyPress signup notifications 540 // If the user is created from the WordPress Add User screen, don't send BuddyPress signup notifications. 551 541 if( in_array( get_current_screen()->id, array( 'user', 'user-network' ) ) ) { 552 // If the Super Admin want to skip confirmation email 542 // If the Super Admin want to skip confirmation email. 553 543 if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) { 554 544 return false; 555 545 556 // WordPress will manage the signup process 546 // WordPress will manage the signup process. 557 547 } else { 558 548 return $user; … … 562 552 * There can be a case where the user was created without the skip confirmation 563 553 * And the super admin goes in pending accounts to resend it. In this case, as the 564 * meta['password'] is not set, the activation url must be WordPress one 554 * meta['password'] is not set, the activation url must be WordPress one. 565 555 */ 566 556 } elseif ( buddypress()->members->admin->signups_page == get_current_screen()->id ) { … … 573 563 } 574 564 575 // Set up activation link 565 // Set up activation link. 576 566 $activate_url = bp_get_activation_page() . "?key=$key"; 577 567 $activate_url = esc_url( $activate_url ); 578 568 579 // Email contents 569 // Email contents. 580 570 $message = sprintf( __( "Thanks for registering! To complete the activation of your account please click the following link:\n\n%1\$s\n\n", 'buddypress' ), $activate_url ); 581 571 $subject = bp_get_email_subject( array( 'text' => __( 'Activate Your Account', 'buddypress' ) ) ); … … 620 610 $message = apply_filters( 'bp_core_activation_signup_user_notification_message', $message, $user, $user_email, $key, $meta ); 621 611 622 // Send the email 612 // Send the email. 623 613 wp_mail( $to, $subject, $message ); 624 614 625 // Set up the $admin_email to pass to the filter 615 // Set up the $admin_email to pass to the filter. 626 616 $admin_email = bp_get_option( 'admin_email' ); 627 617 … … 641 631 do_action( 'bp_core_sent_user_signup_email', $admin_email, $subject, $message, $user, $user_email, $key, $meta ); 642 632 643 // Return false to stop the original WPMU function from continuing 633 // Return false to stop the original WPMU function from continuing. 644 634 return false; 645 635 } … … 657 647 * @param string $sep How to separate the various items within the page title. 658 648 * @param string $seplocation Direction to display title. 659 *660 649 * @return string New page title. 661 650 */ … … 663 652 global $bp, $paged, $page, $_wp_theme_features; 664 653 665 // If this is not a BP page, just return the title produced by WP 654 // If this is not a BP page, just return the title produced by WP. 666 655 if ( bp_is_blog_page() ) { 667 656 return $title; 668 657 } 669 658 670 // If this is a 404, let WordPress handle it 659 // If this is a 404, let WordPress handle it. 671 660 if ( is_404() ) { 672 661 return $title; 673 662 } 674 663 675 // If this is the front page of the site, return WP's title 664 // If this is the front page of the site, return WP's title. 676 665 if ( is_front_page() || is_home() ) { 677 666 return $title; 678 667 } 679 668 680 // Return WP's title if not a BuddyPress page 669 // Return WP's title if not a BuddyPress page. 681 670 if ( ! is_buddypress() ) { 682 671 return $title; 683 672 } 684 673 685 // Setup an empty title parts array 674 // Setup an empty title parts array. 686 675 $title_parts = array(); 687 676 … … 689 678 $displayed_user_name = bp_get_displayed_user_fullname(); 690 679 691 // Displayed user 680 // Displayed user. 692 681 if ( ! empty( $displayed_user_name ) && ! is_404() ) { 693 682 694 // Get the component's ID to try and get its name 683 // Get the component's ID to try and get its name. 695 684 $component_id = $component_name = bp_current_component(); 696 685 697 // Set empty subnav name 686 // Set empty subnav name. 698 687 $component_subnav_name = ''; 699 688 700 // Use the component nav name 689 // Use the component nav name. 701 690 if ( ! empty( $bp->bp_nav[$component_id] ) ) { 702 691 $component_name = _bp_strip_spans_from_title( $bp->bp_nav[ $component_id ]['name'] ); 703 692 704 // Fall back on the component ID 693 // Fall back on the component ID. 705 694 } elseif ( ! empty( $bp->{$component_id}->id ) ) { 706 695 $component_name = ucwords( $bp->{$component_id}->id ); 707 696 } 708 697 709 // Append action name if we're on a member component sub-page 698 // Append action name if we're on a member component sub-page. 710 699 if ( ! empty( $bp->bp_options_nav[ $component_id ] ) && ! empty( $bp->canonical_stack['action'] ) ) { 711 700 $component_subnav_name = wp_filter_object_list( $bp->bp_options_nav[ $component_id ], array( 'slug' => bp_current_action() ), 'and', 'name' ); … … 716 705 } 717 706 718 // If on the user profile's landing page, just use the fullname 707 // If on the user profile's landing page, just use the fullname. 719 708 if ( bp_is_current_component( $bp->default_component ) && ( bp_get_requested_url() === bp_displayed_user_domain() ) ) { 720 709 $title_parts[] = $displayed_user_name; 721 710 722 // Use component name on member pages 711 // Use component name on member pages. 723 712 } else { 724 713 $title_parts = array_merge( $title_parts, array_map( 'strip_tags', array( … … 727 716 ) ) ); 728 717 729 // If we have a subnav name, add it separately for localization 718 // If we have a subnav name, add it separately for localization. 730 719 if ( ! empty( $component_subnav_name ) ) { 731 720 $title_parts[] = strip_tags( $component_subnav_name ); … … 733 722 } 734 723 735 // A single group 724 // A single group. 736 725 } elseif ( bp_is_active( 'groups' ) && ! empty( $bp->groups->current_group ) && ! empty( $bp->bp_options_nav[ $bp->groups->current_group->slug ] ) ) { 737 726 $subnav = isset( $bp->bp_options_nav[ $bp->groups->current_group->slug ][ bp_current_action() ]['name'] ) ? $bp->bp_options_nav[ $bp->groups->current_group->slug ][ bp_current_action() ]['name'] : ''; 738 727 $title_parts = array( $bp->bp_options_title, $subnav ); 739 728 740 // A single item from a component other than groups 729 // A single item from a component other than groups. 741 730 } elseif ( bp_is_single_item() ) { 742 731 $title_parts = array( $bp->bp_options_title, $bp->bp_options_nav[ bp_current_item() ][ bp_current_action() ]['name'] ); 743 732 744 // An index or directory 733 // An index or directory. 745 734 } elseif ( bp_is_directory() ) { 746 735 $current_component = bp_current_component(); 747 736 748 // No current component (when does this happen?) 737 // No current component (when does this happen?). 749 738 $title_parts = array( _x( 'Directory', 'component directory title', 'buddypress' ) ); 750 739 … … 753 742 } 754 743 755 // Sign up page 744 // Sign up page. 756 745 } elseif ( bp_is_register_page() ) { 757 746 $title_parts = array( __( 'Create an Account', 'buddypress' ) ); 758 747 759 // Activation page 748 // Activation page. 760 749 } elseif ( bp_is_activation_page() ) { 761 750 $title_parts = array( __( 'Activate Your Account', 'buddypress' ) ); 762 751 763 // Group creation page 752 // Group creation page. 764 753 } elseif ( bp_is_group_create() ) { 765 754 $title_parts = array( __( 'Create a Group', 'buddypress' ) ); 766 755 767 // Blog creation page 756 // Blog creation page. 768 757 } elseif ( bp_is_create_blog() ) { 769 758 $title_parts = array( __( 'Create a Site', 'buddypress' ) ); 770 759 } 771 760 772 // Strip spans 761 // Strip spans. 773 762 $title_parts = array_map( '_bp_strip_spans_from_title', $title_parts ); 774 763 775 // sep on right, so reverse the order764 // Sep on right, so reverse the order. 776 765 if ( 'right' == $seplocation ) { 777 766 $title_parts = array_reverse( $title_parts ); 778 767 } 779 768 780 // Get the blog name, so we can check if the original $title included it 769 // Get the blog name, so we can check if the original $title included it. 781 770 $blogname = get_bloginfo( 'name', 'display' ); 782 771 … … 789 778 $title_tag_compatibility = (bool) ( ! empty( $_wp_theme_features['title-tag'] ) || strstr( $title, $blogname ) ); 790 779 791 // Append the site title to title parts if theme supports title tag 780 // Append the site title to title parts if theme supports title tag. 792 781 if ( true === $title_tag_compatibility ) { 793 782 $title_parts[] = $blogname; … … 798 787 } 799 788 800 // Pad the separator with 1 space on each side 789 // Pad the separator with 1 space on each side. 801 790 $prefix = str_pad( $sep, strlen( $sep ) + 2, ' ', STR_PAD_BOTH ); 802 791 803 // Join the parts together 792 // Join the parts together. 804 793 $new_title = join( $prefix, array_filter( $title_parts ) ); 805 794 806 // Append the prefix for pre `title-tag` compatibility 795 // Append the prefix for pre `title-tag` compatibility. 807 796 if ( false === $title_tag_compatibility ) { 808 797 $new_title = $new_title . $prefix; … … 832 821 * less than 4.0, and should be removed at a later date. 833 822 * 834 * @param string $title_part 835 * 823 * @param string $title_part Title part to clean up. 836 824 * @return string 837 825 */ … … 851 839 * 852 840 * @param WP_Post $menu_item The menu item. 853 *854 841 * @return WP_Post The modified WP_Post object. 855 842 */ … … 859 846 } 860 847 861 // Prevent a notice error when using the customizer 848 // Prevent a notice error when using the customizer. 862 849 $menu_classes = $menu_item->classes; 863 850 … … 867 854 868 855 // We use information stored in the CSS class to determine what kind of 869 // menu item this is, and how it should be treated 856 // menu item this is, and how it should be treated. 870 857 preg_match( '/\sbp-(.*)-nav/', $menu_classes, $matches ); 871 858 872 // If this isn't a BP menu item, we can stop here 859 // If this isn't a BP menu item, we can stop here. 873 860 if ( empty( $matches[1] ) ) { 874 861 return $menu_item; … … 894 881 break; 895 882 896 // Don't show the Register link to logged-in users 883 // Don't show the Register link to logged-in users. 897 884 case 'register' : 898 885 if ( is_user_logged_in() ) { … … 903 890 904 891 // All other BP nav items are specific to the logged-in user, 905 // and so are not relevant to logged-out users 892 // and so are not relevant to logged-out users. 906 893 default: 907 894 if ( is_user_logged_in() ) { … … 914 901 } 915 902 916 // If component is deactivated, make sure menu item doesn't render 903 // If component is deactivated, make sure menu item doesn't render. 917 904 if ( empty( $menu_item->url ) ) { 918 905 $menu_item->_invalid = true; 919 906 920 // Highlight the current page 907 // Highlight the current page. 921 908 } else { 922 909 $current = bp_get_requested_url(); … … 936 923 937 924 /** 938 * Populate BuddyPress user nav items for the customizer 925 * Populate BuddyPress user nav items for the customizer. 939 926 * 940 927 * @since 2.3.3 941 928 * 942 * @param array $items The array of menu items 943 * @param string $type The requested type 944 * @param string $object The requested object name 945 * @param integer $page The page num being requested 929 * @param array $items The array of menu items. 930 * @param string $type The requested type. 931 * @param string $object The requested object name. 932 * @param integer $page The page num being requested. 946 933 * @return array The paginated BuddyPress user nav items. 947 934 */ … … 973 960 974 961 /** 975 * Set BuddyPress item navs for the customizer 962 * Set BuddyPress item navs for the customizer. 976 963 * 977 964 * @since 2.3.3 … … 1012 999 * 1013 1000 * @param string $q SQL query. 1014 *1015 1001 * @return string 1016 1002 */ … … 1044 1030 * @param string $edit_link The edit link. 1045 1031 * @param int $post_id Post ID. 1046 *1047 1032 * @return bool|string Will be a boolean (false) if $post_id is 0. Will be a string (the unchanged edit link) 1048 1033 * otherwise … … 1064 1049 * @param bool $load_mentions True to load mentions assets, false otherwise. 1065 1050 * @param bool $mentions_enabled True if mentions are enabled. 1066 *1067 1051 * @return bool True if mentions scripts should be loaded. 1068 1052 */
Note: See TracChangeset
for help on using the changeset viewer.