Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/30/2019 11:52:07 AM (3 weeks ago)
Author:
imath
Message:

Add a BuddyPress Blocks category to the Block Editor

This blocks category does not come with BuddyPress blocks. It is there to let BuddyPress developers use it to tidy their BuddyPress blocks into the different Block selectors of the Block Editor.

Fixes #8116

File:
1 edited

Legend:

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

    r11999 r12418  
    11361136}
    11371137add_filter( 'admin_body_class', 'bp_core_admin_body_classes' );
     1138
     1139/**
     1140 * Adds a BuddyPress category to house BuddyPress blocks.
     1141 *
     1142 * @since 5.0.0
     1143 *
     1144 * @param array   $categories Array of block categories.
     1145 * @param WP_Post $post       Post being loaded.
     1146 */
     1147function bp_block_category( $categories = array(), WP_Post $post ) {
     1148    /**
     1149     * Filter here to add/remove the supported post types for the BuddyPress blocks category.
     1150     *
     1151     * @since 5.0.0
     1152     *
     1153     * @param array $value The list of supported post types. Defaults to WordPress built-in ones.
     1154     */
     1155    $post_types = apply_filters( 'bp_block_category_post_types', array( 'post', 'page' ) );
     1156
     1157    if ( ! $post_types ) {
     1158        return $categories;
     1159    }
     1160
     1161    // Get the post type of the current item.
     1162    $post_type = get_post_type( $post );
     1163
     1164    if ( ! in_array( $post_type, $post_types, true ) ) {
     1165        return $categories;
     1166    }
     1167
     1168    return array_merge( $categories, array(
     1169        array(
     1170            'slug'  => 'buddypress',
     1171            'title' => __( 'BuddyPress', 'buddypress' ),
     1172            'icon'  => 'buddicons-buddypress-logo',
     1173        ),
     1174    ) );
     1175}
     1176add_filter( 'block_categories', 'bp_block_category', 1, 2 );
Note: See TracChangeset for help on using the changeset viewer.