Example #1
0
 static function load_theme_functions()
 {
     global $pagenow;
     // If bbPress is being deactivated, do not load any more files
     if (bbp_is_deactivation()) {
         return;
     }
     if (!defined('WP_INSTALLING') || !empty($pagenow) && 'wp-activate.php' !== $pagenow) {
         bbp_locate_template('bbpresskr-functions.php', true);
     }
 }
Example #2
0
/**
 * bbPress 2.2 uses dynamic roles, and hooks very early into WP_Roles and the option_wp_user_roles section.
 * This is done to override the default role and apply relevant caps, but then deletes our custom caps as a result.
 * This functions queries the DB directly and re-adds these caps to the bbPress roles depending on settings
 * @param unknown $roles
 */
function em_bbp_get_caps_for_role($caps, $role)
{
    global $em_capabilities_array, $wpdb;
    if (bbp_is_deactivation()) {
        return $caps;
    }
    //get the non-dynamic role from the wp_options table
    $roles = maybe_unserialize($wpdb->get_var("SELECT option_value FROM {$wpdb->options} WHERE option_name='wp_user_roles'"));
    //loop through the original role if it exists and add our em caps to the bp role
    if (!empty($roles[$role])) {
        foreach ($roles[$role]['capabilities'] as $cap_name => $has_cap) {
            if (array_key_exists($cap_name, $em_capabilities_array)) {
                $caps[$cap_name] = $has_cap;
            }
        }
    }
    return $caps;
}
Example #3
0
 /**
  * Setup the admin hooks, actions and filters
  *
  * @since bbPress (r2646)
  * @access private
  *
  * @uses add_action() To add various actions
  * @uses add_filter() To add various filters
  */
 private function setup_actions()
 {
     // Bail to prevent interfering with the deactivation process
     if (bbp_is_deactivation()) {
         return;
     }
     /** General Actions ***************************************************/
     add_action('bbp_admin_menu', array($this, 'admin_menus'));
     // Add menu item to settings menu
     add_action('bbp_admin_head', array($this, 'admin_head'));
     // Add some general styling to the admin area
     add_action('bbp_admin_notices', array($this, 'activation_notice'));
     // Add notice if not using a bbPress theme
     add_action('bbp_register_admin_style', array($this, 'register_admin_style'));
     // Add green admin style
     add_action('bbp_register_admin_settings', array($this, 'register_admin_settings'));
     // Add settings
     add_action('bbp_activation', array($this, 'new_install'));
     // Add menu item to settings menu
     add_action('admin_enqueue_scripts', array($this, 'enqueue_styles'));
     // Add enqueued CSS
     add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
     // Add enqueued JS
     add_action('wp_dashboard_setup', array($this, 'dashboard_widget_right_now'));
     // Forums 'Right now' Dashboard widget
     add_action('admin_bar_menu', array($this, 'admin_bar_about_link'), 15);
     // Add a link to bbPress about page to the admin bar
     /** Ajax **************************************************************/
     add_action('wp_ajax_bbp_suggest_topic', array($this, 'suggest_topic'));
     add_action('wp_ajax_nopriv_bbp_suggest_topic', array($this, 'suggest_topic'));
     add_action('wp_ajax_bbp_suggest_user', array($this, 'suggest_user'));
     add_action('wp_ajax_nopriv_bbp_suggest_user', array($this, 'suggest_user'));
     /** Filters ***********************************************************/
     // Modify bbPress's admin links
     add_filter('plugin_action_links', array($this, 'modify_plugin_action_links'), 10, 2);
     // Map settings capabilities
     add_filter('bbp_map_meta_caps', array($this, 'map_settings_meta_caps'), 10, 4);
     // Hide the theme compat package selection
     add_filter('bbp_admin_get_settings_sections', array($this, 'hide_theme_compat_packages'));
     // Allow keymasters to save forums settings
     add_filter('option_page_capability_bbpress', array($this, 'option_page_capability_bbpress'));
     /** Network Admin *****************************************************/
     // Add menu item to settings menu
     add_action('network_admin_menu', array($this, 'network_admin_menus'));
     /** Dependencies ******************************************************/
     // Allow plugins to modify these actions
     do_action_ref_array('bbp_admin_loaded', array(&$this));
 }
/**
 * Add the default role to the current user if needed
 *
 * This function will bail if the forum is not global in a multisite
 * installation of WordPress, or if the user is marked as spam or deleted.
 *
 * @since bbPress (r3380)
 *
 * @uses is_user_logged_in() To bail if user is not logged in
 * @uses bbp_get_user_role() To bail if user already has a role
 * @uses bbp_is_user_inactive() To bail if user is inactive
 * @uses bbp_allow_global_access() To know whether to save role to database
 * @uses bbp_get_user_role_map() To get the WP to BBP role map array
 * @uses bbp_get_default_role() To get the site's default forums role
 * @uses get_option()
 *
 * @return If not multisite, not global, or user is deleted/spammed
 */
function bbp_set_current_user_default_role()
{
    /** Sanity ****************************************************************/
    // Bail if deactivating bbPress
    if (bbp_is_deactivation()) {
        return;
    }
    // Catch all, to prevent premature user initialization
    if (!did_action('set_current_user')) {
        return;
    }
    // Bail if not logged in or already a member of this site
    if (!is_user_logged_in()) {
        return;
    }
    // Get the current user ID
    $user_id = bbp_get_current_user_id();
    // Bail if user already has a forums role
    if (bbp_get_user_role($user_id)) {
        return;
    }
    // Bail if user is marked as spam or is deleted
    if (bbp_is_user_inactive($user_id)) {
        return;
    }
    /** Ready *****************************************************************/
    // Load up bbPress once
    $bbp = bbpress();
    // Get whether or not to add a role to the user account
    $add_to_site = bbp_allow_global_access();
    // Get the current user's WordPress role. Set to empty string if none found.
    $user_role = bbp_get_user_blog_role($user_id);
    // Get the role map
    $role_map = bbp_get_user_role_map();
    /** Forum Role ************************************************************/
    // Use a mapped role
    if (isset($role_map[$user_role])) {
        $new_role = $role_map[$user_role];
        // Use the default role
    } else {
        $new_role = bbp_get_default_role();
    }
    /** Add or Map ************************************************************/
    // Add the user to the site
    if (true === $add_to_site) {
        // Make sure bbPress roles are added
        bbp_add_forums_roles();
        $bbp->current_user->add_role($new_role);
        // Don't add the user, but still give them the correct caps dynamically
    } else {
        $bbp->current_user->caps[$new_role] = true;
        $bbp->current_user->get_role_caps();
    }
}
Example #5
0
 /**
  * Setup the default hooks and actions
  *
  * @since bbPress (r2644)
  * @access private
  * @uses add_action() To add various actions
  */
 private function setup_actions()
 {
     // Add actions to plugin activation and deactivation hooks
     add_action('activate_' . $this->basename, 'bbp_activation');
     add_action('deactivate_' . $this->basename, 'bbp_deactivation');
     // If bbPress is being deactivated, do not add any actions
     if (bbp_is_deactivation($this->basename)) {
         return;
     }
     // Array of bbPress core actions
     $actions = array('setup_theme', 'setup_current_user', 'register_post_types', 'register_post_statuses', 'register_taxonomies', 'register_shortcodes', 'register_views', 'register_theme_packages', 'load_textdomain', 'add_rewrite_tags', 'add_rewrite_rules', 'add_permastructs');
     // Add the actions
     foreach ($actions as $class_action) {
         add_action('bbp_' . $class_action, array($this, $class_action), 5);
     }
     // All bbPress actions are setup (includes bbp-core-hooks.php)
     do_action_ref_array('bbp_after_setup_actions', array(&$this));
 }
Example #6
0
	/**
	 * Setup the default hooks and actions
	 *
	 * @since bbPress (r2644)
	 * @access private
	 * @uses add_action() To add various actions
	 */
	private function setup_actions() {

		// Add actions to plugin activation and deactivation hooks
		add_action( 'activate_'   . $this->basename, 'bbp_activation'   );
		add_action( 'deactivate_' . $this->basename, 'bbp_deactivation' );

		// If bbPress is being deactivated, do not add any actions
		if ( bbp_is_deactivation( $this->basename ) )
			return;

		// Array of bbPress core actions
		$actions = array(
			'setup_theme',              // Setup the default theme compat
			'setup_current_user',       // Setup currently logged in user
			'register_post_types',      // Register post types (forum|topic|reply)
			'register_post_statuses',   // Register post statuses (closed|spam|orphan|hidden)
			'register_taxonomies',      // Register taxonomies (topic-tag)
			'register_shortcodes',      // Register shortcodes (bbp-login)
			'register_views',           // Register the views (no-replies)
			'register_theme_packages',  // Register bundled theme packages (bbp-theme-compat/bbp-themes)
			'load_textdomain',          // Load textdomain (bbpress)
			'add_rewrite_tags',         // Add rewrite tags (view|user|edit|search)
			'add_rewrite_rules',        // Generate rewrite rules (view|edit|paged|search)
			'add_permastructs'          // Add permalink structures (view|user|search)
		);

		// Add the actions
		foreach ( $actions as $class_action )
			add_action( 'bbp_' . $class_action, array( $this, $class_action ), 5 );

		// All bbPress actions are setup (includes bbp-core-hooks.php)
		do_action_ref_array( 'bbp_after_setup_actions', array( &$this ) );
	}