Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Check that BP_Group_Extension Class Exists
- if( class_exists( 'BP_Group_Extension' ) ) {
- class Buddypress_Groups_Custom_Meta extends BP_Group_Extension {
- public function __construct() {
- $this->setup_hooks();
- }
- private function setup_hooks() {
- // Add new Metabox for XLSuite Fields (ID & Updated At)
- add_action( 'bp_groups_admin_meta_boxes', array( $this, 'bp_groups_admin_meta_boxes' ) );
- // Store Group Meta after Admin Save
- add_action( 'bp_group_admin_edit_after', array( $this, 'bp_group_admin_content_edit_after'), 10, 1 );
- }
- /**
- * Register a new Metabox in Group Admin UI's Edit Group Panel
- * Create Meta Box for Content Editor
- * Create Meta Box for XLSuite ID and XLSuite Updated At
- * @uses add_meta_box() to register our meta box
- */
- public function bp_groups_admin_meta_boxes() {
- add_meta_box(
- 'bp_groups_metabox_content',
- __( 'Group Information', 'wplms_customizer' ),
- array( &$this, 'bp_groups_admin_info_metabox'),
- get_current_screen()->id,
- 'normal',
- 'high'
- );
- }
- /**
- * Display the Content Metabox and Field
- * @param BP_Groups_Group $item the group being edited
- * @uses groups_get_groupmeta() to get the featured attribute of the group
- * @uses checked() to eventually add a checked attribute if the group is featured
- * @uses wp_nonce_field() for security reasons
- */
- public function bp_groups_admin_info_metabox( $group = false ) {
- if( empty( $group ) )
- return;
- $prefix = 'bp_group_';
- // Set-up Custom Fields to Create
- $custom_fields = array();
- $custom_fields[] = array(
- 'label' => __('Group Content','wplms-customizer'),
- 'desc' => __('The Group Content Editor.','wplms-customizer'),
- 'id' => $prefix.'content_editor',
- 'type' => 'editor'
- );
- ?>
- <table class="form-table meta_box">
- <tbody>
- <?php
- foreach ( $custom_fields as $custom_field ) {
- $custom_field_value = groups_get_groupmeta( $group->id, $custom_field['id'] );
- if ( $custom_field['type'] == 'editor' ) { ?>
- <tr>
- <th>
- <label for="<?php echo $custom_field['id']; ?>"><?php echo $custom_field['label']; ?></label>
- </th>
- <td>
- <?php wp_editor( $custom_field_value, $custom_field['id'] , array(
- 'wpautop' => true,
- 'media_buttons' => true,
- 'teeny' => true,
- 'textarea_rows' => '4',
- 'textarea_cols' => '30',
- 'tinymce' => array(
- 'theme_advanced_buttons1' => 'save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,cut,copy,paste,pastetext,pasteword,',
- 'theme_advanced_buttons2' => "styleselect,formatselect,fontselect,fontsizeselect,",
- 'theme_advanced_buttons3' => ",bullist,numlist,|,outdent,indent,blockquote,|,link,anchor,image,|,insertdate,forecolor,backcolor,|,tablecontrols,|,hr,|,fullscreen",
- 'theme_advanced_buttons4' => "",
- 'theme_advanced_text_colors' => '0f3156,636466,0486d3',
- ),
- 'quicktags' => array(
- 'buttons' => 'strong,em,link,block,del,ins,img,code,ul,ol,li,close'
- )
- ) ); ?>
- <span class="description"><?php echo $custom_field['desc']; ?></span>
- </td>
- </tr>
- <?php
- } else {
- ?>
- <tr>
- <th>
- <label for="<?php echo $custom_field['id']; ?>"><?php echo $custom_field['label']; ?></label>
- </th>
- <td>
- <input id="<?php echo $custom_field['id']; ?>" type="<?php echo $custom_field['type']; ?>" name="<?php echo $custom_field['id']; ?>" value="<?php echo $custom_field_value; ?>" size="20" />
- <span class="description"><?php echo $custom_field['desc']; ?></span>
- </td>
- </tr>
- <?php
- }
- }
- ?>
- </tbody>
- </table>
- <?php
- wp_nonce_field( 'bp_group_content_save_' . $group->id, 'bp_group_content_admin' );
- }
- /**
- * Saves the Content Field
- * @param integer $group_id the group id for the group being edited
- * @uses check_admin_referer() for security reasons
- * @uses groups_get_groupmeta() to get the existing group meta
- * @uses groups_update_groupmeta() to update the group meta
- * @uses groups_delete_groupmeta() to remove the group meta if empty
- */
- function bp_group_admin_content_edit_after( $group_id = 0 ) {
- if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) || empty( $group_id ) )
- return false;
- check_admin_referer('bp_group_content_save_' . $group_id, 'bp_group_content_admin')
- $content = groups_get_groupmeta( $group_id, 'bp_group_content_editor' );
- $new_content = '';
- if ( array_key_exists( 'bp_group_content_editor', $_POST ) && isset( $_POST['bp_group_content_editor'] ) && ! empty( trim( $_POST['bp_group_content_editor'] ) ) ) {
- $new_content = $_POST['bp_group_content_editor'];
- }
- if( ! empty( $new_content ) ) {
- groups_update_groupmeta($group_id, 'bp_group_content_editor', $new_content);
- } elseif ( ! empty( $content ) ) {
- groups_delete_groupmeta($group_id, 'bp_group_content_editor');
- }
- }
- }
- /**
- * Initalize the Buddypress_Groups_Custom_Meta Class
- *
- * @since 1.0.0
- * @uses bp_is_active([component]) to check the group component is active
- */
- function buddypress_groups_custom_meta() {
- if(bp_is_active('groups')) {
- return new Buddypress_Groups_Custom_Meta();
- }
- }
- add_action('bp_init', 'buddypress_groups_custom_meta');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement