Skip to:
Content

BuddyPress.org

Changeset 8458


Ignore:
Timestamp:
05/28/2014 05:23:47 PM (6 years ago)
Author:
johnjamesjacoby
Message:

Groups -- Update bp_groups_filter_kses():

  • Add phpdoc block.
  • Add inline doc.
  • Document bp_groups_filter_kses filter.
  • Use wp_kses_allowed_html() instead of touching $allowedtags global. Pass a custom buddypress-groups context, so it can be targeted.
  • Rename some local variables to improve code clarity.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-filters.php

    r7790 r8458  
    3434add_filter( 'bp_get_group_description_excerpt', 'make_clickable', 9 );
    3535
    36 add_filter( 'bp_get_group_name',                    'wp_filter_kses', 1 );
    37 add_filter( 'bp_get_group_permalink',               'wp_filter_kses', 1 );
     36add_filter( 'bp_get_group_name',                    'wp_filter_kses',        1 );
     37add_filter( 'bp_get_group_permalink',               'wp_filter_kses',        1 );
    3838add_filter( 'bp_get_group_description',             'bp_groups_filter_kses', 1 );
    39 add_filter( 'bp_get_group_description_excerpt',     'wp_filter_kses', 1 );
    40 add_filter( 'groups_group_name_before_save',        'wp_filter_kses', 1 );
    41 add_filter( 'groups_group_description_before_save', 'wp_filter_kses', 1 );
     39add_filter( 'bp_get_group_description_excerpt',     'wp_filter_kses',        1 );
     40add_filter( 'groups_group_name_before_save',        'wp_filter_kses',        1 );
     41add_filter( 'groups_group_description_before_save', 'wp_filter_kses',        1 );
    4242
    4343add_filter( 'bp_get_group_description',         'stripslashes' );
     
    6666add_filter( 'bp_get_group_total_members',    'bp_core_number_format' );
    6767
    68 function bp_groups_filter_kses( $content ) {
    69     global $allowedtags;
    70 
    71     $groups_allowedtags                  = $allowedtags;
    72     $groups_allowedtags['a']['class']    = array();
    73     $groups_allowedtags['img']           = array();
    74     $groups_allowedtags['img']['src']    = array();
    75     $groups_allowedtags['img']['alt']    = array();
    76     $groups_allowedtags['img']['class']  = array();
    77     $groups_allowedtags['img']['width']  = array();
    78     $groups_allowedtags['img']['height'] = array();
    79     $groups_allowedtags['img']['class']  = array();
    80     $groups_allowedtags['img']['id']     = array();
    81     $groups_allowedtags['code']          = array();
    82     $groups_allowedtags = apply_filters( 'bp_groups_filter_kses', $groups_allowedtags );
    83 
    84     return wp_kses( $content, $groups_allowedtags );
     68/**
     69 * Filter output of Group Description through WordPress's KSES API.
     70 *
     71 * @since BuddyPress (1.1.0)
     72 *
     73 * @param string $content
     74 * @return string
     75 */
     76function bp_groups_filter_kses( $content = '' ) {
     77
     78    /**
     79     * Note that we don't immediately bail if $content is empty. This is because
     80     * WordPress's KSES API calls several other filters that might be relevant
     81     * to someone's workflow (like `pre_kses`)
     82     */
     83
     84    // Get allowed tags using core WordPress API allowing third party plugins
     85    // to target the specific `buddypress-groups` context.
     86    $allowed_tags = wp_kses_allowed_html( 'buddypress-groups' );
     87
     88    // Add our own tags allowed in group descriptions
     89    $allowed_tags['a']['class']    = array();
     90    $allowed_tags['img']           = array();
     91    $allowed_tags['img']['src']    = array();
     92    $allowed_tags['img']['alt']    = array();
     93    $allowed_tags['img']['class']  = array();
     94    $allowed_tags['img']['width']  = array();
     95    $allowed_tags['img']['height'] = array();
     96    $allowed_tags['img']['class']  = array();
     97    $allowed_tags['img']['id']     = array();
     98    $allowed_tags['code']          = array();
     99
     100    /**
     101     * Filter HTML elements allowed for a given context.
     102     *
     103     * @since BuddyPress (1.1.0)
     104     *
     105     * @param string $allowed_tags Allowed tags, attributes, and/or entities.
     106     */
     107    $tags = apply_filters( 'bp_groups_filter_kses', $allowed_tags );
     108
     109    // Return KSES'ed content, allowing the above tags
     110    return wp_kses( $content, $tags );
    85111}
    86112
Note: See TracChangeset for help on using the changeset viewer.