Skip to:
Content

bbPress.org

Ticket #1823: 1823.patch

File 1823.patch, 3.7 KB (added by johnjamesjacoby, 13 years ago)
  • bbp-includes/bbp-core-actions.php

     
    7676 */
    7777add_action( 'bbp_init', 'bbp_load_textdomain',         2   );
    7878add_action( 'bbp_init', 'bbp_setup_option_filters',    4   );
     79add_action( 'bbp_init', 'bbp_setup_function_filters',  6   );
    7980add_action( 'bbp_init', 'bbp_register_post_types',     10  );
    8081add_action( 'bbp_init', 'bbp_register_post_statuses',  12  );
    8182add_action( 'bbp_init', 'bbp_register_taxonomies',     14  );
  • bbp-includes/bbp-core-functions.php

     
    1010// Exit if accessed directly
    1111if ( !defined( 'ABSPATH' ) ) exit;
    1212
     13/** Function Map **************************************************************/
     14
     15/**
     16 * Get the default function map
     17 *
     18 * @since bbPress (r3898)
     19 * @return array Filtered option names and values
     20 */
     21function bbp_get_function_map() {
     22
     23        // Default function
     24        return apply_filters( 'bbp_get_function_map', array(
     25
     26                /** User Meta *********************************************************/
     27
     28                'get_user_meta'    => 'get_user_meta',
     29                'add_user_meta'    => 'add_user_meta',
     30                'update_user_meta' => 'update_user_meta',
     31                'delete_user_meta' => 'delete_user_meta',
     32
     33                /** Post Meta *********************************************************/
     34
     35                'get_post_meta'    => 'get_post_meta',
     36                'add_post_meta'    => 'add_post_meta',
     37                'update_post_meta' => 'update_post_meta',
     38                'delete_post_meta' => 'delete_post_meta',
     39
     40                /** Blog Option *******************************************************/
     41
     42                'get_option'       => 'get_option',
     43                'add_option'       => 'add_option',
     44                'update_option'    => 'update_option',
     45                'delete_option'    => 'delete_option',
     46
     47                /** Site Option *******************************************************/
     48
     49                'get_site_option'    => 'get_site_option',
     50                'add_site_option'    => 'add_site_option',
     51                'update_site_option' => 'update_site_option',
     52                'delete_site_option' => 'delete_site_option'
     53
     54        ) );
     55}
     56
     57/**
     58 * Add filters to each mapped function and allow them to be overloaded from
     59 * inside the $bbp->functions array.
     60 *
     61 * @since bbPress (r3898)
     62 * @uses bbp_get_function_map() To get default functions
     63 * @uses add_filter() To add filters to 'pre_option_{$key}'
     64 * @uses do_action() Calls 'bbp_add_function_filters'
     65 */
     66function bbp_setup_function_filters() {
     67
     68        // Add filters to each bbPress option
     69        foreach ( bbp_get_function_map() as $key => $value )
     70                add_filter( 'bbp_pre_function_' . $key, 'bbp_pre_get_function' );
     71
     72        // Allow previously activated plugins to append their own options.
     73        do_action( 'bbp_setup_function_filters' );
     74}
     75
     76/**
     77 * Filter default functions and allow them to be overloaded from inside the
     78 * $bbp->functions array.
     79 *
     80 * @since bbPress (r3898)
     81 * @param bool $value Optional. Default value false
     82 * @return mixed false if not overloaded, mixed if set
     83 */
     84function bbp_pre_get_function( $value = false ) {
     85        $bbp = bbpress();
     86
     87        // Remove the filter prefix
     88        $function = str_replace( 'bbp_pre_function_', '', current_filter() );
     89
     90        // Check the options global for preset value
     91        if ( !empty( $bbp->functions[$function] ) )
     92                $value = $bbp->functions[$function];
     93
     94        // Always return a value, even if false
     95        return $value;
     96}
     97
     98/**
     99 * Get the function to call given a certain circumstance.
     100 *
     101 * @since bbPress (r3898)
     102 * @param string $name The function to call
     103 * @return string The function that will be called
     104 */
     105function bbp_get_function( $name = false ) {
     106        return apply_filters( 'bbp_pre_function_' . $name, $name );
     107}
     108
    13109/** Versions ******************************************************************/
    14110
    15111/**