Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/11/2011 11:59:27 PM (14 years ago)
Author:
boonebgorges
Message:

Adds column to the Pages Dashboard panel with information about associated BP components, if any. Adds meta box to Edit Page panel with information about the associated page. Fixes #3027. Fixes #3028

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-functions.php

    r4107 r4122  
    7575
    7676    return apply_filters( 'bp_core_get_page_names', $pages );
     77}
     78
     79/**
     80 * Adds an addition column to the Pages screen (edit.php?post_type=page) to display whether a
     81 * page is linked to a BP component
     82 *
     83 * @package BuddyPress Core
     84 * @since 1.3
     85 *
     86 * @param array $columns The column setup array, passed by manage_pages_columns
     87 * @return array $columns The column setup array with the BP column added
     88 */
     89function bp_core_add_pages_column_header( $columns ) {
     90    $columns['bp-pages'] = '<div class="vers"><img src="' . BP_PLUGIN_URL . '/bp-core/images/logo-column-header.png" title="' . __( 'Is this page associated with a BuddyPress component?', 'buddypress' ) . '" /></div>';
     91   
     92    return $columns;
     93}
     94add_filter( 'manage_pages_columns', 'bp_core_add_pages_column_header' );
     95
     96/**
     97 * Adds the associated component name to the Pages column
     98 *
     99 * For most components, the translatable name can be fetched out of the $bp global. 'register' and
     100 * 'activate' are handled as special cases.
     101 *
     102 * @package BuddyPress Core
     103 * @since 1.3
     104 */
     105function bp_core_add_pages_column_content() {
     106    global $bp;
     107   
     108    foreach( (array)$bp->pages as $component => $page_data ) {
     109        if ( $page_data->id == get_the_ID() ) {
     110            if ( isset( $bp->{$component}->name ) ) {
     111                $text = $bp->{$component}->name;
     112            } else if ( 'register' == $component ) {
     113                $text = __( 'Register', 'buddypress' );
     114            } else if ( 'activate' == $component ) {
     115                $text = __( 'Activate', 'buddypress' );
     116            } else {
     117                $text = '';
     118            }
     119           
     120            echo apply_filters( 'bp_core_pages_column_text', $text, $component );
     121            break;
     122        }
     123    }
     124   
     125}
     126add_filter( 'manage_pages_custom_column', 'bp_core_add_pages_column_content' );
     127
     128
     129/**
     130 * Adds a meta box to the Edit Page panel containing BP information
     131 *
     132 * @package BuddyPress Core
     133 * @since 1.3
     134 * @uses add_meta_box() to add the meta box
     135 */
     136function bp_core_add_meta_box() {
     137    $post_id = isset( $_GET['post'] ) ? $_GET['post'] : false;
     138   
     139    // Don't show the meta box on the New Page screen
     140    if ( !$post_id )
     141        return;
     142   
     143    add_meta_box( 'bp_pages_meta', __( 'BuddyPress', 'buddypress' ), 'bp_core_meta_box_content', 'page', 'side' );
     144}
     145add_action( 'admin_init', 'bp_core_add_meta_box' );
     146
     147/**
     148 * Renders the content of the Edit Page meta box
     149 *
     150 * @package BuddyPress Core
     151 * @since 1.3
     152 */
     153function bp_core_meta_box_content() {
     154    global $bp;
     155
     156    $post_id = isset( $_GET['post'] ) ? $_GET['post'] : false;
     157   
     158    // Get the name of the associated component
     159    foreach( (array)$bp->pages as $component => $page_data ) {
     160        if ( $page_data->id == $post_id ) {
     161            if ( isset( $bp->{$component}->name ) ) {
     162                $text = $bp->{$component}->name;
     163            } else if ( 'register' == $component ) {
     164                $text = __( 'Register', 'buddypress' );
     165            } else if ( 'activate' == $component ) {
     166                $text = __( 'Activate', 'buddypress' );
     167            } else {
     168                $text = '';
     169            }
     170           
     171            $bp->this_dashboard_edit_page_name =  apply_filters( 'bp_core_meta_box_page_name', $text, $component );
     172            break;
     173        }
     174    }
     175?>
     176
     177    <?php if ( !empty( $bp->this_dashboard_edit_page_name ) ) : ?>
     178        <p><?php printf( __( 'This page is associated with a BuddyPress component: <strong>%1$s</strong>.', 'buddypress' ), $bp->this_dashboard_edit_page_name ) ?></p>
     179    <?php else : ?>
     180        <p><?php _e( 'This page is not associated with a BuddyPress component.', 'buddypress' ) ?></p>
     181    <?php endif ?>
     182   
     183    <p><?php printf( __( 'Visit the <a href="%1$s">BuddyPress component setup panel</a> to change your BuddyPress component settings.', 'buddypress' ), network_admin_url( 'admin.php?page=bp-general-settings' ) ) ?></p>
     184
     185<?php
    77186}
    78187
Note: See TracChangeset for help on using the changeset viewer.