Skip to:
Content

BuddyPress.org

Ticket #4525: 4525.001.patch

File 4525.001.patch, 4.2 KB (added by DJPaul, 12 years ago)
  • bp-themes/bp-default/functions.php

    function bp_dtheme_setup() { 
    112112                add_theme_support( 'custom-header', $custom_header_args );
    113113        }
    114114
    115         if ( !is_admin() ) {
    116                 // Register buttons for the relevant component templates
     115        // Register buttons for the relevant component templates
     116        // Friends button
     117        if ( bp_is_active( 'friends' ) )
     118                add_action( 'bp_member_header_actions',    'bp_add_friend_button',           5 );
     119
     120        // Activity button
     121        if ( bp_is_active( 'activity' ) )
     122                add_action( 'bp_member_header_actions',    'bp_send_public_message_button',  20 );
     123
     124        // Messages button
     125        if ( bp_is_active( 'messages' ) )
     126                add_action( 'bp_member_header_actions',    'bp_send_private_message_button', 20 );
     127
     128        // Group buttons
     129        if ( bp_is_active( 'groups' ) ) {
     130                add_action( 'bp_group_header_actions',     'bp_group_join_button',           5 );
     131                add_action( 'bp_group_header_actions',     'bp_group_new_topic_button',      20 );
     132                add_action( 'bp_directory_groups_actions', 'bp_group_join_button' );
     133        }
     134
     135        // Blog button
     136        if ( bp_is_active( 'blogs' ) )
     137                add_action( 'bp_directory_blogs_actions',  'bp_blogs_visit_blog_button' );
     138}
     139add_action( 'after_setup_theme', 'bp_dtheme_setup' );
     140endif;
     141
     142/**
     143 * Backward compatibility for a backpat problem introduced in BP 1.6 when AJAX callbacks were hooked to admin-ajax.php.
     144 *
     145 * While handling AJAX via admin-ajax.php, is_admin() and DOING_AJAX are both true. BP-Default's registered the button
     146 * actions in a block with an !is_admin() check, so the add_actions were ignored when we returned templates with buttons.
     147 * This function is hooked to after_setup_theme with priority 11, so that it happens after bp_dtheme_setup() is run, and
     148 * re-adds the button actions if they are missing.
     149 *
     150 * @see bp_dtheme_setup()
     151 * @since BuddyPress (1.7)
     152 */
     153function bp_dtheme_fix_buttons() {
     154        if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) {
     155
    117156                // Friends button
    118                 if ( bp_is_active( 'friends' ) )
    119                         add_action( 'bp_member_header_actions',    'bp_add_friend_button',          5 );
     157                if ( bp_is_active( 'friends' ) && ! has_action( 'bp_member_header_actions', 'bp_add_friend_button' ) && ! has_action( 'bp_member_header_actions', 'bp_add_friend_button' ) )
     158                        add_action( 'bp_member_header_actions', 'bp_add_friend_button', 5 );
    120159
    121160                // Activity button
    122                 if ( bp_is_active( 'activity' ) )
    123                         add_action( 'bp_member_header_actions',    'bp_send_public_message_button', 20 );
     161                if ( bp_is_active( 'activity' ) && ! has_action( 'bp_member_header_actions', 'bp_send_public_message_button' ) )
     162                        add_action( 'bp_member_header_actions', 'bp_send_public_message_button', 20 );
    124163
    125164                // Messages button
    126                 if ( bp_is_active( 'messages' ) )
    127                         add_action( 'bp_member_header_actions',    'bp_send_private_message_button', 20 );
     165                if ( bp_is_active( 'messages' ) && ! has_action( 'bp_member_header_actions', 'bp_send_private_message_button' ) )
     166                        add_action( 'bp_member_header_actions', 'bp_send_private_message_button', 20 );
    128167
    129168                // Group buttons
    130169                if ( bp_is_active( 'groups' ) ) {
    131                         add_action( 'bp_group_header_actions',     'bp_group_join_button',           5 );
    132                         add_action( 'bp_group_header_actions',     'bp_group_new_topic_button',      20 );
    133                         add_action( 'bp_directory_groups_actions', 'bp_group_join_button' );
    134                 }
    135170
    136                 // Blog button
    137                 if ( bp_is_active( 'blogs' ) )
    138                         add_action( 'bp_directory_blogs_actions',  'bp_blogs_visit_blog_button' );
     171                        if ( ! has_action( 'bp_group_header_actions', 'bp_group_join_button' ) )
     172                                add_action( 'bp_group_header_actions', 'bp_group_join_button', 5 );
     173
     174                        if ( ! has_action( 'bp_group_header_actions', 'bp_group_new_topic_button' ) )
     175                                add_action( 'bp_group_header_actions', 'bp_group_new_topic_button', 20 );
     176
     177                        if ( ! has_action( 'bp_directory_groups_actions', 'bp_group_join_button' ) )
     178                                add_action( 'bp_directory_groups_actions', 'bp_group_join_button' );
     179                }
    139180        }
    140181}
    141 add_action( 'after_setup_theme', 'bp_dtheme_setup' );
    142 endif;
     182add_action( 'after_setup_theme', 'bp_dtheme_fix_buttons', 11 );
    143183
    144184if ( !function_exists( 'bp_dtheme_enqueue_scripts' ) ) :
    145185/**