bp_add_cover_image_inline_css( bool $return = false )
Add inline css to display the component’s single item cover photo.
Description
Parameters
- $return
-
(Optional) True to get the inline css.
Default value: false
Return
(null|array|false) The inline css or an associative array containing the css rules and the style handle.
Source
File: bp-core/bp-core-cssjs.php
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 | function bp_add_cover_image_inline_css( $return = false ) { $bp = buddypress(); // Find the component of the current item. if ( bp_is_user() ) { // User is not allowed to upload cover photos // no need to carry on. if ( bp_disable_cover_image_uploads() ) { return ; } $cover_image_object = array ( 'component' => 'xprofile' , 'object' => $bp ->displayed_user ); } elseif ( bp_is_group() ) { // Users are not allowed to upload cover photos for their groups // no need to carry on. if ( bp_disable_group_cover_image_uploads() ) { return ; } $cover_image_object = array ( 'component' => 'groups' , 'object' => $bp ->groups->current_group ); } else { $cover_image_object = apply_filters( 'bp_current_cover_image_object_inline_css' , array () ); } // Bail if no component were found. if ( empty ( $cover_image_object [ 'component' ] ) || empty ( $cover_image_object [ 'object' ] ) || ! bp_is_active( $cover_image_object [ 'component' ], 'cover_image' ) ) { return ; } // Get the settings of the cover photo feature for the current component. $params = bp_attachments_get_cover_image_settings( $cover_image_object [ 'component' ] ); // Bail if no params. if ( empty ( $params ) ) { return ; } // Try to call the callback. if ( is_callable ( $params [ 'callback' ] ) ) { $object_dir = $cover_image_object [ 'component' ]; if ( 'xprofile' === $object_dir ) { $object_dir = 'members' ; } $cover_image = bp_attachments_get_attachment( 'url' , array ( 'object_dir' => $object_dir , 'item_id' => $cover_image_object [ 'object' ]->id, ) ); if ( empty ( $cover_image ) ) { if ( ! empty ( $params [ 'default_cover' ] ) ) { $cover_image = $params [ 'default_cover' ]; } } $inline_css = call_user_func_array( $params [ 'callback' ], array ( array ( 'cover_image' => esc_url_raw( $cover_image ), 'component' => sanitize_key( $cover_image_object [ 'component' ] ), 'object_id' => (int) $cover_image_object [ 'object' ]->id, 'width' => (int) $params [ 'width' ], 'height' => (int) $params [ 'height' ], ) ) ); // Finally add the inline css to the handle. if ( ! empty ( $inline_css ) ) { // Used to get the css when Ajax setting the cover photo. if ( true === $return ) { return array ( 'css_rules' => '<style>' . "\n" . $inline_css . "\n" . '</style>' , 'handle' => $params [ 'theme_handle' ], ); } wp_add_inline_style( $params [ 'theme_handle' ], $inline_css ); } else { return false; } } } |
Changelog
Version | Description |
---|---|
BuddyPress 2.4.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.